nikefido Posted February 19, 2008 Share Posted February 19, 2008 I have an upload section in my form. I want the option to upload a file to NOT be required input. I tried testing to see if the $_FILES['uploaded'] was set using "isset" but that seems to be set every time no matter what. How can I test if there was no file uploaded? (the user didn't hit browse & there's no input in the text field)? Quote Link to comment Share on other sites More sharing options...
duclet Posted February 19, 2008 Share Posted February 19, 2008 Can you do a print_r on $_FILES['uploaded']? I forgot of the top of my head what the default value for that is so please output that and post here. Quote Link to comment Share on other sites More sharing options...
nikefido Posted February 19, 2008 Author Share Posted February 19, 2008 Array ( [name] => [type] => [tmp_name] => [error] => 4 => 0 ) ...which doesn't make a lot of sense - I tried to test if 'name' was empty ( if !empty($_FILES['uploaded']['name']) ) Quote Link to comment Share on other sites More sharing options...
nikefido Posted February 19, 2008 Author Share Posted February 19, 2008 I suppose i could validate based on the error? Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted February 19, 2008 Share Posted February 19, 2008 There is an error code for no file uploaded: http://us3.php.net/manual/en/features.file-upload.errors.php Quote Link to comment Share on other sites More sharing options...
duclet Posted February 19, 2008 Share Posted February 19, 2008 Yup, just use: <?php if($_FILES['uploaded']['error'] === UPLOAD_ERR_NO_FILE) { ... do something if file is no file was uploaded ... } ?> Quote Link to comment Share on other sites More sharing options...
nikefido Posted February 19, 2008 Author Share Posted February 19, 2008 thanks all (no SOLVED button?) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.