Sunday, October 28, 2012

php file upload error messages in a php array

Hope this will be useful to someone, all the php file upload error codes and messages in an array.

<?php

$error_codes = array(
        0=>"There is no error, the file uploaded with success",
        1=>"The uploaded file exceeds the upload_max_filesize directive in php.ini",
        2=>"The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
        3=>"The uploaded file was only partially uploaded",
        4=>"No file was uploaded",
        6=>"Missing a temporary folder",
        7=>"Failed to write file to disk",
        8=>"A PHP extension stopped the file upload"
);

/* Posssible Usage */

if($_FILES["userfile"]["error"] > 0){
   
  $code = $_FILES["userfile"]["error"];
  echo $error_codes[$code];
}
else{
 
 //do the processing
}
 
?>

No comments:

Post a Comment