ID: 35783
Comment by: cuisdy at gmail dot com
Reported By: brian at gtv dot com
Status: Open
Bug Type: Feature/Change Request
Operating System: FreeBSD 5.4
PHP Version: 5.1.1
New Comment:
@brian at gtv dot com: getimagesize doesn't return anything in the
['mime'] index either.
Previous Comments:
------------------------------------------------------------------------
[2005-12-29 08:13:42] brian at gtv dot com
You can add the following code to the Switch / Case statement in the
Reproduce code included above. It's a different mime type that can also
be used to identify ICO images. The addition of this code does not
resolve the problem. It is only to highlight the subtleties of the issue
and to help make it easier getting the new feature added. Here's the
additional Case statement:
case 'image/x-icon':
if($type != "ICO") { $err_text .= "Image is
wrong type. It is a ICO
and should be a {$type}.<br>\n"; }
break;
------------------------------------------------------------------------
[2005-12-23 10:14:46] [email protected]
Not a bug, but a feature request.
------------------------------------------------------------------------
[2005-12-23 09:37:06] brian at gtv dot com
Description:
------------
I am using the GetImageSize function in a function I wrote which
validates the width, height, and type of an image as the user uploads it
to my website. On my website I have setup a number of different fields
where a user can upload different images that are very specific to the
width, height, and type that I allow for each field.
For example in field one I allow the user to upload an image of
width=512, height=315, and type=BMP and in field two I allow the user to
upload an image of width=48, height=48, and type=ICO and in field three
I allow the user to upload an image of width=176, height=36, and
type=GIF.
My problem is that the GetImageSize function does not currently support
the ICO file type and the image/vnd.microsoft.icon mime type. When I
upload a ICO image and use the GetImageSize function on the image the
$image_size_array[0], $image_size_array[1], and $image_size_array[2] are
blank as well as the $image_size_array['mime'] being blank.
This means I can't validate the width, height, or file type of the ICO
images that are being uploaded. Which defeats the purpose of validating
the files for a good number of the images in this section of my
website.
>From my review of the bug report DB I have not seen anyone else report
this problem and I'm a little shocked to see that no one else would need
support for ICO images in PHP. It may just be the type of website I'm
building and the type of company I work for - a software company - where
we are using these ICO images that are uploaded from our customers in
our software. However I think it would be a good idea to add support
into PHP for this fairly common image format that is widely used.
Reproduce code:
---------------
function validateGraphic($image, $width, $height, $type){
$err_text = "";
if(!isset($image)) { $err_text .= "You must select an image file to
upload.<br>\n"; }
if($image['error'] > '0') { $err_text .= "There was an error uploading
the image file.<br>\n"; }
if($image['error'] == '0') {
$image_size_array = getimagesize($image['tmp_name']);
//check the width of the image
if($image_size_array[0] > $width) { $err_text .= "Image is too
wide.
It is {$image_size_array[0]} pixels wide.<br>\n"; }
if($image_size_array[0] < $width) { $err_text .= "Image is too
narrow. It is {$image_size_array[0]} pixels wide.<br>\n"; }
//check the height of the image
if($image_size_array[1] > $height) { $err_text .= "Image is too
tall.
It is {$image_size_array[1]} pixels tall.<br>\n"; }
if($image_size_array[1] < $height) { $err_text .= "Image is too
short. It is {$image_size_array[1]} pixels tall.<br>\n"; }
//check the type of the image
switch($image_size_array['mime']) {
case 'image/gif':
if($type != "GIF") { $err_text .= "Image is
wrong type. It is a GIF
and should be a {$type}.<br>\n"; }
break;
case 'image/jpeg':
if($type != "JPG") { $err_text .= "Image is
wrong type. It is a JPG
and should be a {$type}.<br>\n"; }
break;
case 'image/vnd.microsoft.icon':
if($type != "ICO") { $err_text .= "Image is
wrong type. It is a ICO
and should be a {$type}.<br>\n"; }
break;
case 'image/bmp':
if($type != "BMP") { $err_text .= "Image is
wrong type. It is a BMP
and should be a {$type}.<br>\n"; }
break;
default:
$err_text .= "Image is wrong type. It is a
{$image_size_array['mime']} and should be a {$type}.<br>\n";
break;
}
}
return $err_text;
}
This function is called in this type of manner:
$error_txt .= validateGraphic($_FILES['upload1'], '142', '114', 'ICO');
Expected result:
----------------
When function is called in manner described and the ICO image that
matches is uploaded I expect no error messages to be produced, the file
to be uploaded, and the entry to be added into my DB.
I'm expecting the GetImageSize function to handle the ICO file type and
the image/vnd.microsoft.icon mime type, but because it can't this is
breaking my validation function.
Actual result:
--------------
Instead I get the following error messages:
Image is too narrow. It is pixels wide.
Image is too short. It is pixels tall.
Image is wrong type. It is a and should be a ICO.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=35783&edit=1