Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #35783 : Using GetImageSize with ICO files and the image/vnd.microsoft.icon mime type
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 20th June 00:53
php-bugs@lists.php.net (brian at gtv dot
External User
 
Posts: 1
Default #35783 : Using GetImageSize with ICO files and the image/vnd.microsoft.icon mime type



From: brian at gtv dot com
Operating system: FreeBSD 5.4
PHP version: 5.1.1
PHP Bug Type: GetImageSize related
Bug description: Using GetImageSize with ICO files and the image/vnd.microsoft.icon mime type

Description:
------------


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 bug report at http://bugs.php.net/?id=35783&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=35783&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=35783&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=35783&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=35783&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=35783&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=35783&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=35783&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=35783&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=35783&r=support
Expected behavior: http://bugs.php.net/fix.php?id=35783&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=35783&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=35783&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=35783&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35783&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=35783&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=35783&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=35783&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=35783&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=35783&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=35783&r=mysqlcfg
  Reply With Quote


  sponsored links


2 20th June 00:53
derick
External User
 
Posts: 1
Default #35783 : Using GetImageSize with ICO files and the image/vnd.microsoft.icon mime type



ID: 35783
Updated by: derick@php.net
Reported By: brian at gtv dot com
Status: Open
-Bug Type: GetImageSize related
+Bug Type: Feature/Change Request
Operating System: FreeBSD 5.4
PHP Version: 5.1.1
New Comment:

Not a bug, but a feature request.


Previous Comments:
------------------------------------------------------------------------

[2005-12-23 09:37:06] brian at gtv dot com

Description:
------------


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
  Reply With Quote
3 20th June 20:51
php-bugs@lists.php.net (brian at gtv dot
External User
 
Posts: 1
Default #35783 : Using GetImageSize with ICO files and the image/vnd.microsoft.icon mime type


ID: 35783
User updated by: brian at gtv 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:

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;


Previous Comments:
------------------------------------------------------------------------

[2005-12-23 10:14:46] derick@php.net

Not a bug, but a feature request.

------------------------------------------------------------------------

[2005-12-23 09:37:06] brian at gtv dot com

Description:
------------


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
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666