englishcodemonkey Posted January 17, 2009 Share Posted January 17, 2009 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! Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 17, 2009 Share Posted January 17, 2009 Did you check the upload section in the php manual where the errors are documented? Quote Link to comment Share on other sites More sharing options...
sniperscope Posted January 17, 2009 Share Posted January 17, 2009 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.'; } Quote Link to comment Share on other sites More sharing options...
englishcodemonkey Posted January 17, 2009 Author Share Posted January 17, 2009 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 Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted January 17, 2009 Share Posted January 17, 2009 http://us.php.net/manual/en/features.file-upload.errors.php It refers to the MAX_FILE_SIZE attribute of the form field... somebody probably would have noticed, but you would have needed to post the form Quote Link to comment Share on other sites More sharing options...
englishcodemonkey Posted January 17, 2009 Author Share Posted January 17, 2009 Thank you guys, definately a newbie mistake! Thanks again , problem solved :D Quote Link to comment 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.