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)? Link to comment https://forums.phpfreaks.com/topic/91932-validating-upload-file-form-validation/ 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. Link to comment https://forums.phpfreaks.com/topic/91932-validating-upload-file-form-validation/#findComment-470760 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']) ) Link to comment https://forums.phpfreaks.com/topic/91932-validating-upload-file-form-validation/#findComment-470770 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? Link to comment https://forums.phpfreaks.com/topic/91932-validating-upload-file-form-validation/#findComment-470777 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 Link to comment https://forums.phpfreaks.com/topic/91932-validating-upload-file-form-validation/#findComment-470781 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 ... } ?> Link to comment https://forums.phpfreaks.com/topic/91932-validating-upload-file-form-validation/#findComment-470784 Share on other sites More sharing options...
nikefido Posted February 19, 2008 Author Share Posted February 19, 2008 thanks all (no SOLVED button?) Link to comment https://forums.phpfreaks.com/topic/91932-validating-upload-file-form-validation/#findComment-470793 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.