PHP form question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

PHP form question.

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
lostinphp
Forum Commoner
Posts: 44
Joined: Wed Jul 27, 2005 5:10 am
Location: Paris,France.

Post 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!
User avatar
quadoc
Forum Contributor
Posts: 137
Joined: Fri Jul 01, 2005 5:33 pm
Location: Atlanta, GA

Post 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? :?
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

Just check files array is populated.

Code: Select all

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