Jump to content

$_FILES


kapz22

Recommended Posts

How do i check if a file has been selected to uplload?

 

I tried doing:

 

if ($_FILES["userfile"] != null) {

echo "a file has been selected to upload"; exit;

} else {

echo "a file has not been selected"; exit;

}

 

this does not work and i dont know why. please can some one help.

thanks

Link to comment
Share on other sites

$_FILES["userfile"] will be an array. The php.net upload documentation shows what elements it contains - http://us3.php.net/manual/en/features.file-upload.php

 

About the only time it would be NULL would be if uploads are not enabled on your server or the HTTP request for your page was not the result of a valid upload form with a form field by the name "userfile".

 

You can also see what is in the array using the following code -

 

echo "<pre>",print_r($_FILES,true),"</pre>";

Link to comment
Share on other sites

The ['error'] element will be a zero value if a file was selected and uploaded successfully.

 

Nothing else really makes sense. The ["name"] element can be set, but there can still be upload errors and the ["tmp_name"] element will never be the string "none".

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.