Forum Moderators: coopster

Message Too Old, No Replies

how to do a if userfile exists?

         

mgworek

3:41 pm on Nov 8, 2006 (gmt 0)

10+ Year Member



I have a script working for uploading a photo.

I have 2 choices on the form, upload a photo or a checkbox for no photo.

I want to to do a check so if they checked no photo as well as picked a file to upload, it reports back that they need to fix it.

how do you check to see if userfile exists?

here is what i define in the script.

$userfile = $_FILES['userfile']['name'];

phparion

4:17 pm on Nov 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if($_FILES['userfile']['name']!= "") {
//UPLOAD FILE
}
else {
// do not upload
}

of to be more secure change your IF to

if(!empty(trim($_FILES['userfile']['name'] )) ) {

this will remove spaces then will check if there is any value coming in this field ........

to go to the next level ,, use regex to determine the expected path and extension of the file

mgworek

6:06 pm on Nov 8, 2006 (gmt 0)

10+ Year Member



Thank you.

dont i feel like a dork.

I was trying that code before i posted with no luck, i go back using what you replied with to see what i was doing wrong.

I was defining my sql statement when I wasn't running it so it looked like nothing was happening. (I was using the code somewhere else before using it for what i said in my post)