Link to home
Start Free TrialLog in
Avatar of daniel_smith
daniel_smithFlag for United States of America

asked on

PHP Upload file error: UPLOAD_ERR_EXTENSION

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

Open in new window

Avatar of cwiedmann
cwiedmann

From http://php.net/manual/en/features.file-upload.errors.php:

UPLOAD_ERR_EXTENSION
Value: 8; A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.

What extensions do you have installed?
Avatar of daniel_smith

ASKER

Wish i could tell you, no clue how to tell.
Create a page with the following code, and look at the output.
<?php
echo phpinfo();

Open in new window

i got that, only extenstion i see is PHP

That seems unlikely.  Most installations would have at least a few extensions.  What do you see as the next sections after "HTTP Headers information" in your phpinfo output?
HTTP Request  GET /phpinfo.php HTTP/1.1  
Accept  application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*  
Accept-Language  en-US  
User-Agent  Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; OfficeLiveConnector.1.4; OfficeLivePatch.1.3)  
Accept-Encoding  gzip, deflate  
Host  www.x-x-x-x-x-x.com  
Connection  Keep-Alive  
Cookie  __utma=202877714.1843906341.1268058660.1270052690.1270056387.13; __utmz=202877714.1268058660.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmc=202877714  
I'm looking for the sections after the HTTP Headers information section, not the contents of that section.  The following sections should be for the extensions that are installed.
bz2
calendar
ctype
curl
date
exif
ftp
gd
gettext
hash
iconv
ldap
libxml
mime_magic
mysql
mysqli
openssl
pcre
PDO
pgsql
session
SimpleXML
sockets
SSL
standard
sysvmsg
tokenizer
wddx
xml
Nothing jumps out at me in that list.  Do you have access to the web server's error log file?  Can you check in there to see if any of the extensions logged error messages when you uploaded the file?
ASKER CERTIFIED SOLUTION
Avatar of daniel_smith
daniel_smith
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah, I would have expected CANT_WRITE in that case too.