Primary links
PHP File Upload Errors Explained
admin — Wed, 27/06/2007 - 10:12am
UPLOAD_ERR_OK (error 0)
Means : File upload was successful.
UPLOAD_ERR_INI_SIZE (error 1)
Means : The uploaded file exceeds the upload_max_filesize directive in php.ini.
UPLOAD_ERR_FORM_SIZE (error 2)
Means : The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
UPLOAD_ERR_PARTIAL (error 3)
Means : The uploaded file was only partially uploaded.
UPLOAD_ERR_NO_FILE (error 4)
Means : No file was uploaded.
UPLOAD_ERR_NO_TMP_DIR (error 6)
Means : Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.
UPLOAD_ERR_CANT_WRITE (error 7)
Means : Failed to write file to disk. Introduced in PHP 5.1.0.
UPLOAD_ERR_EXTENSION (error 8)
Means : File upload stopped by extension. Introduced in PHP 5.2.0.
Note: These became PHP constants in PHP 4.3.0.
The following code snippet can be used toeffectively debug your upload code.
<?
if ($_REQUEST['Submit'] == "Send File") {
$uploaddir = '/home/yourserver/myfiles/';
$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 {
switch ($_FILES['userfile']["error"]) {
case 1:
echo("The uploaded file exceeds the upload_max_filesize directive (".ini_get("upload_max_filesize").") in php.ini.");
break;
case 2:
echo("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.");
break;
case 3:
echo("The uploaded file was only partially uploaded.");
break;
case 4:
echo("No file was uploaded.");
break;
case 6:
echo("Missing a temporary folder.");
break;
default:
echo("An unknown file upload error occured");
break;
}
}
}
?>
<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1024000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" name="Submit" value="Send File" />
</form>
User login
Follow Us
Who's online
Who's new
- Nisha
- linnaeus
- Yameen
- TalleyReedy
- admin

