PHP form question.
Moderator: General Moderators
PHP form question.
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...
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.
We've had a lot of conversations about file uploading, so have a poke around, and post back some specific questions.
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!
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!
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? 
Just check files array is populated.
Code: Select all
if(!empty($_FILES['field_name']['name'])){
// file upload
}else{
// no file upload
}