Jump to content

[SOLVED] print_r($_FILES) what does this error mean?


englishcodemonkey

Recommended Posts

Hi guys,

 

I am trying to upload a file to my hosting account on godaddy, and it works some of the time, and the rest of the time it displays the error below:

 

I'm using print_r($_FILES) to display the error, what does error=>2  mean?

 

(
    [userfile] => Array
        (
            [name] => absolutetreas.gif
            [type] => 
            [tmp_name] => 
            [error] => 2
            [size] => 0
        )

)

 

This is the code i'm using to upload the pic:

$uploaddir = '../images/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

}

 

Thanks so much!

 

Link to comment
Share on other sites

Hi, hope this solve your problem.

 

     

$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
      $upload_path = '../images/'; // The place the files will be uploaded to (currently a 'files' directory).
	  $upload_path = $upload_path.'/';

   $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
  
  
   if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
	  die('The file you attempted to upload is too large.'); // if we upload large file then we get error.
   if(!is_writable($upload_path))
	  die('You cannot upload to the specified directory, please CHMOD it to 777.'); // if we have no enough permission then got error.

   if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)){
                        // if everything is fine then we upload file and go to somewhere else
		 header ('location: whereeveryouwantogo.php');
	 } else {
		 echo 'There was an error during the file upload.  Please try again.';
	}

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.