troubleshooting Question

PHP Upload file error: UPLOAD_ERR_EXTENSION

Avatar of daniel_smith
daniel_smithFlag for United States of America asked on
PHPApache Web Server
11 Comments1 Solution1883 ViewsLast Modified:
Doing a file upload off a image submited in a form.

receiving this error: UPLOAD_ERR_EXTENSION


function file_upload_error_message($error_code) {
    switch ($error_code) { 
        case UPLOAD_ERR_INI_SIZE: 
            return 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; 
        case UPLOAD_ERR_FORM_SIZE: 
            return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; 
        case UPLOAD_ERR_PARTIAL: 
            return 'The uploaded file was only partially uploaded'; 
        case UPLOAD_ERR_NO_FILE: 
            return 'No file was uploaded'; 
        case UPLOAD_ERR_NO_TMP_DIR: 
            return 'Missing a temporary folder'; 
        case UPLOAD_ERR_CANT_WRITE: 
            return 'Failed to write file to disk'; 
        case UPLOAD_ERR_EXTENSION: 
            return 'File upload stopped by extension'; 
        default: 
            return 'Unknown upload error'; 
    } 
} 



	echo "Upload: " . $_FILES["imgfile"]["name"] . "<br />";
    echo "Type: " . $_FILES["imgfile"]["type"] . "<br />";
    echo "Size: " . ($_FILES["imgfile"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["imgfile"]["tmp_name"] . "<br />";

    if (file_exists("missrock_uploads/" . $_FILES["imgfile"]["name"]))
    {
    	echo $_FILES["imgfile"]["name"] . " already exists. ";
    }else{
      if(move_uploaded_file($_FILES["imgfile"]["tmp_name"],"missrock_uploads/".$_FILES["imgfile"]["name"]))
      {
      	echo "Stored in: " . "missrock_uploads/".$_FILES["imgfile"]["name"]."<br>";	
      }else{
      	echo "There was an error uploading the file ".$_FILES['imgfile']['name'].", please try again!<br><br>";
      	$error_message = file_upload_error_message($_FILES['imgfile']['error']); 
      	echo $error_message;
      }
    }
ASKER CERTIFIED SOLUTION
daniel_smith

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros