Solved

Upload image and get other form elements

Posted on 2006-11-16
5
211 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

739 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