MIME type image check not working

This is a discussion on "MIME type image check not working" within the PHP Forum section. This forum, and the thread "MIME type image check not working are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jul 15th, 2007, 03:04
SuperMember

SuperMember
Join Date: Apr 2007
Location: Sydney
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
MIME type image check not working

Hi, Im using this code to check an image file before upload. The test file definately has the mime type 'image/pjpeg' however the line

Code: Select all
if ($type != "image/pjpeg")
always comes back true.

Any ideas why??

Thanks,

Nathan.



Code: Select all
 
if (!is_uploaded_file($_FILES['userphoto']['tmp_name'])) 
 {
     $error = "you didn't select a file to upload.<br />";
 } 
 else 
 {
     if ($_FILES['userphoto']['size'] > $maxfilesize) 
  {
         $error = "your image file was too large.<br />";
         unlink($_FILES['userphoto']['tmp_name']);
     } 
  else 
  {
         $ext = strrchr($_FILES['userphoto']['name'], ".");
         if ($ext != ".jpg" AND $ext != ".jpeg" AND $ext != ".JPG" AND $ext != ".JPEG" ) 
   {
             $error = "your file was an unacceptable type.<br />";
             unlink($_FILES['userphoto']['tmp_name']);
   } 
   else 
   {
    $image = $_FILES['userphoto']['tmp_name'];
    if (!getimagesize($image))
    { 
          $error = "not a valid image - image size function failed."; 
          unlink($_FILES['userphoto']['tmp_name']);
       }
    else
    {
     $type = $_FILES['userphoto']['type'];
     if ($type != "image/pjpeg")
     {
      $error = "not a valid image - MIME type rejected '$type'."; 
           unlink($_FILES['userphoto']['tmp_name']);
     }
     else
     { 
      if ($_SESSION['photo'] != "noimage.jpg") 
      {
                   unlink("./images/userimages/".$_SESSION['photo']);
               }
               $newname = $_SESSION['user_name'].$ext;
               move_uploaded_file($_FILES['userphoto']['tmp_name'],"./images/userimages/".$newname);
                mysql_query("UPDATE techs SET photo='$newname' WHERE user_name='$user_name'") or die (mysql_error());
               $_SESSION['photo'] = $newname;
     }
          }
      }
  }
 }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jul 15th, 2007, 03:33
SuperMember

SuperMember
Join Date: Apr 2007
Location: Sydney
Posts: 159
Thanks: 0
Thanked 0 Times in 0 Posts
Re: MIME type image check not working

ok ignore this.. the "'s got me again....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
image check, mime type

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Content Mime Type for .master Corey Bryant ASP.NET Forum 2 Dec 5th, 2007 19:28
Rollover image links - eek...why aren't they working?? supanova75 Web Page Design 7 Nov 15th, 2007 12:47
Changing image not working in Firefox PoetAlley JavaScript Forum 5 Sep 27th, 2007 14:12
Image Display on Mouseover not Working in IE7 thefmgirl JavaScript Forum 5 Jan 22nd, 2007 09:51
MIME type for email with CDONTS GillBates Classic ASP 8 Dec 1st, 2003 15:19


All times are GMT. The time now is 02:19.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42