maxelct Posted July 30, 2007 Share Posted July 30, 2007 Dear All I have what I think is a very simple piece of code. <?php if (isset($_POST['submitted'])){ if(!isset($_FILES['upload'])){ echo '<br />a file was selected'; }else{ echo '<br />a file was not selected'; } }//end of submitted ?> <form enctype="multipart/form-data" action="upload_test.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="16000000" /> <fieldset><legend>Select a File</legend> <input type="file" name="upload" /> </fieldset> <input type="submit" name="submit" value="submit me" /> <input type="hidden" name="submitted" value="TRUE" /> </form> : : I want a simple test for if the user has picked a file or not. I figured that if(isset$_files['upload']){....}else{...} might be a good one but it doesn't work. If you have no file selected and press submit then you get "No file selected". If you then select a file and press submit you sill get no file selected. Worse, if you then re-load the page, select a file and press submit you STILL get "No file selected" I expect I am doing something stupid here... can someone please advise! Thanks Edward m Quote Link to comment https://forums.phpfreaks.com/topic/62554-very-simple-test-for-file-field-doesnt-word/ Share on other sites More sharing options...
hitman6003 Posted July 30, 2007 Share Posted July 30, 2007 <?php if (is_array($_FILES['upload']) && $_FILES['upload']['error'] == 0) { echo '<br />a file was selected'; } else { echo '<br />a file was not selected'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/62554-very-simple-test-for-file-field-doesnt-word/#findComment-311366 Share on other sites More sharing options...
maxelct Posted July 31, 2007 Author Share Posted July 31, 2007 Dear Hitman Thanks very much - needless to say worked first time. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/62554-very-simple-test-for-file-field-doesnt-word/#findComment-312105 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.