...

View Full Version : file upload confirmation question



Bobafart
03-03-2008, 01:22 AM
I have a form where the user has the option to upload an image for a group creation script I am making.

it works great if the user uploads

but if the user decides not to upload anything and fill out the rest of the fields then I get into problems.. the file conditional is still met and "nothing" is uploaded to the server unforunately



if(isset($_FILES['uploadedfile']['name'])){

the above conditional is met whether or not the user decides to upload file in my form.. how do I make it so that the conditional is only met if an upload is made?

thanks

_Aerospace_Eng_
03-03-2008, 01:25 AM
Try

if(isset($_FILES['uploadedfile'])){
You may want to read this: http://www.htmlgoodies.com/beyond/webmaster/article.php/3560181

Bobafart
03-03-2008, 02:03 AM
no difference.. it still treats it as a positive condition that is met even when no file is uploaded...

CFMaBiSmAd
03-03-2008, 02:18 AM
If a type="file" field exists but nothing was entered at the time the form was submitted, the $_FILES array will be set and the ['error'] element for the field name will contain a value of 4 -

UPLOAD_ERR_NO_FILE
Value: 4; No file was uploaded.

Ref - http://www.php.net/manual/en/features.file-upload.errors.php

digitalfiz
03-03-2008, 04:26 AM
Just check if its empty instead of if its set.

CFMaBiSmAd
03-03-2008, 05:09 AM
It won't be empty, the ['error'] element will be set. Checking the error element like I posted is the only way to tell if no file was selected and to distinguish this condition from the other errors that could occur for a file upload.

Bobafart
03-03-2008, 10:45 AM
If a type="file" field exists but nothing was entered at the time the form was submitted, the $_FILES array will be set and the ['error'] element for the field name will contain a value of 4 -


Ref - http://www.php.net/manual/en/features.file-upload.errors.php


so do this?



if(($_FILES['uploadedfile']['error'])=='UPLOAD_ERR_NO_FILE'){

CFMaBiSmAd
03-03-2008, 01:59 PM
Yes, except no quotes around - UPLOAD_ERR_NO_FILE



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum