Jump to content

Problem with mime type array when uploading files...


dsartain

Recommended Posts

I'm starting to make a dynamic pic gallery for a friend, and most of her jpg files have the mime type if image/pjpeg.  I want to make sure that she is only uploading images, but I want to allow more than just that one mime type to be uploaded (image/jpeg, image/gif...etc)...It's uploading the file properly, enough to determine the mime type anyway, but it keeps giving me the "You are attempting to upload a file that is not in the image/pjpeg, image/jpeg, image/gif, image/bmp, or image/png format" error...the code for the file upload and mime test is below.  I think my array and foreach loop is right, but I can't think of what else could mess it up...ideas?

 

$userfile_t=$_FILES['userfile_t']['tmp_name'];
$userfile_t_name=$_FILES['userfile_t']['name'];
$userfile_t_size=$_FILES['userfile_t']['size'];
$userfile_t_type=$_FILES['userfile_t']['type'];
$userfile_t_error=$_FILES['userfile_t']['error'];
if($userfile_t_error>0)
{
echo "Problem: ";
switch($userfile_t_error)
{
	case 1: echo "File exceeded upload_max_filesize!"; break;
	case 2: echo "File exceeded max_file_size!"; break;
	case 3: echo "File only partially uploaded!"; break;		
	case 4: echo "No file uploaded!"; break;
}
exit;
}

$mimeTypes = array('image/jpeg', 'image/pjpeg', 'image/gif', 'image/bmp', 'image/png'); 
foreach ($mimeTypes as $type) 
{ 
     if ($userfile_t_type != $type) 
     { 
          echo "Problem: You are attempting to upload a file that is not in the image/pjpeg, image/jpeg, image/gif, image/bmp, or image/png format!<BR />"; 
	  echo "thumbnail<br />";
          echo $userfile_t_type."<BR />"; 
          exit; 
     } 
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.