Jump to content

very simple test for file field - doesn't word


maxelct

Recommended Posts

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.