Solved

Upload image and get other form elements

Posted on 2006-11-16
5
205 Views
Last Modified: 2008-03-06
Hi All,

I have a form that asks the user to enter some personal information and then the last field is to browse for an image to be uploaded.

I see many examples of uploading a file but it is the only field in the form in all these examples. How can I get the other form elements from my script at he same time? Do I have to put them in another PHP page?

Thanks

0
Comment
Question by:knuckle05
  • 2
5 Comments
 
LVL 2

Expert Comment

by:dantuma
ID: 17964893
Hi knuckle05,

You can just put it in the same form.

After the submit you just have to check if a file was submitted.

Put something in it like:

-----------------------------------------------------------------------
if($submit && $_FILES['file']) { // Is there a submit and a selected file

      $file_name = $_FILES['file']['name']; // This is the name of the uploaded file
      $file_temp = $_FILES['file']['tmp_name]'; // This is the temporary file

      // Now move the file to the wanted folder
      move_uploaded_file($file_temp,"yourfolder/$file_name");

}

-----------------------------------------------------------------------


- dantuma
0
 
LVL 1

Author Comment

by:knuckle05
ID: 17987910
Hi dantuma,

Sorry for the delay.

So I can still get my other form elements using the $_GET['field1'] syntax?
0
 
LVL 2

Accepted Solution

by:
dantuma earned 50 total points
ID: 17987970
yes you can.

Use $_FILES for the uploads and $_POST or $_GET for the other form elements.

By the way, important maybe. Your form should contain the following type:
ENCTYPE="multipart/form-data"

like in:

<FORM ENCTYPE="multipart/form-data" ACTION="" METHOD="">

That way the form wil send data and files.

- dantuma
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question