Solved

Upload image and get other form elements

Posted on 2006-11-16
5
179 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now