Page 1 of 1

PHP form question.

Posted: Thu Aug 25, 2005 4:47 pm
by quadoc
I've a form with some inputs and also somewhere in the middle of the form I've a section for file upload. Could some one tells me if I've to create another form just for the upload or how to process the upload if I only use one form? Please post some tips. I'm kind of new to these form thing. :? Thanks...

Posted: Thu Aug 25, 2005 4:55 pm
by feyd
first, you need to make sure you set the enctype attribute in the form tag. Next it's suggested you use MAX_FILE_SIZE hidden fields before the upload fields. Next, make sure you are posting. The file(s) will be in the $_FILES superglobal under the name the fields had.

We've had a lot of conversations about file uploading, so have a poke around, and post back some specific questions.

Posted: Fri Aug 26, 2005 2:21 am
by lostinphp
yeah its definitely possible to have the form and its upload code in the same php file.
make action as php self and include the code to upload a file in the same.
most times im not clear at explaining stuffs..so lemme know if u still dont get wat im saying..i'll show u the way i did it.
happy coding!

Posted: Fri Aug 26, 2005 9:19 am
by quadoc
Thanks for the tips guys. One more questions, does the $_FILES variable get cleared out after the file is uploaded? In my page, the user have the option of upload or not upload a file. So if I check for $_FILES info and the user is not uploading anything and clicks submits and I check for the $_FILES variable that would be invalid right? :?

Posted: Fri Aug 26, 2005 10:15 am
by bokehman
Just check files array is populated.

Code: Select all

if(!empty($_FILES['field_name']['name'])){
    // file upload
}else{
   // no file upload
}