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!

 

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.';
	}

I cant get that code to work either :(. I thought that maybe the picture was too big as well, so on the file upload page i changed the max upload size and still no luck, do you no what error=> 2 stands for? Is it a specific error code? I cant see it in the php manual either!

 

Sorry

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.