Solved

Upload image and get other form elements

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

630 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