Forum Moderators: coopster

Message Too Old, No Replies

Am stuck: Need help with Forms and PHP

upload file and information

         

ChagriLama

3:32 am on Oct 27, 2009 (gmt 0)

10+ Year Member



Hi, I inherited the work on a website. What they needed was to collect information via form. Added form, and the PHP processing and it works just fine. I am a TOTAL newb on PHP, but plowed my way through books, forums, and other people's code to gain some understanding.

Now we need to also upload a file. Uploading a file by itself works fine (store into a table as blob or a file in a directory.)

I cannot figure out how to upload data AND a file in one form. Anyone can walk me through this?

Thank you!

ChagriLama

Zipper

4:14 am on Oct 27, 2009 (gmt 0)

10+ Year Member



It's pretty much the same. You use $_FILES[] to handle the file stuff and $_POST[] to handle the data just like you usually do.

ChagriLama

4:19 am on Oct 27, 2009 (gmt 0)

10+ Year Member



Hmmm.. my main problem is that the browse for a file has one "submit" and the form has another submit and they do not seem to live together well...

Zipper

4:47 am on Oct 27, 2009 (gmt 0)

10+ Year Member



Well, make sure that all the form elements, both file and data, are within one FORM tag. Here's an example.


<form enctype="multipart/form-data" action="upload.php" method="POST">
Data 1 : <input type="text" name="Data1" text="" />
Data 2 : <input type="text" name="Data2" text="" />
File 1: <input type="file" name="File1" />
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input type="submit" value="Submit Form" />
</form>

Get it?

ChagriLama

1:56 pm on Oct 27, 2009 (gmt 0)

10+ Year Member



Zipper, THANKS, Got it! The other "real meat" was in the "service code", what your snippet of code above had as "upload.php". In it, I have to make sure to handle the data entered in "Data1" and "Data2" by using the $_POST['Data1'] and $_POST['Data2'] as well as the file uploaded.

I did just that, and voila! I now have my file uploaded and saved in a directory, and the information about it is sitting in a table.

It looks so simple now that you kicked my head in the right direction <G>... Thank you again.

I am officially "UN-stuck!"

Will follow now threads on checking input provided for "evil things".

(-)cl

Zipper

2:07 pm on Oct 27, 2009 (gmt 0)

10+ Year Member



Haha, glad you figured it out!