Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Upload image and get other form elements

Posted on 2006-11-16
5
Medium Priority
?
220 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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

718 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