Page 2 of 2
Posted: Mon Apr 04, 2005 10:17 am
by cs-web
How do I use them on the uploaded file because I get
Warning: filesize(): Stat failed for Array (errno=2 - No such file or directory) in /home/csweb/public_html/addimage.php on line 17
Fatal error: Call to undefined function: exif_imagetype() in /home/csweb/public_html/addimage.php on line 18
When I do
Code: Select all
$filesize = filesize($_FILES['image']);
$imagefiletype = exif_imagetype($_FILES['image']);
Posted: Mon Apr 04, 2005 10:43 am
by feyd
Code: Select all
$file =& $_FILESї'image'];
if($fileї'error'] === UPLOAD_ERR_OK)
{
$filesize = filesize( $fileї'tmp_name'] );
if( $filesize != $fileї'size'] )
{
die('spoof attempt!');
}
$info = getimagesize( $fileї'tmp_name'] );
$is_jpeg = false;
if( $info === false )
{
if( function_exists( 'exif_imagetype' ) )
{
$info = exif_imagetype( $fileї'tmp_name'] );
if( defined('IMAGETYPE_JPEG') && ($info !== constant('IMAGETYPE_JPEG')) && defined('IMAGETYPE_JP2') )
{
switch($info)
{
case constant('IMAGETYPE_JP2'):
case constant('IMAGETYPE_JPC'):
case constant('IMAGETYPE_JPX'):
case constant('IMAGETYPE_JB2'):
$is_jpeg = true;
break;
default:
break;
}
}
elseif( defined('IMAGETYPE_JPEG') && ($info === constant('IMAGETYPE_JPEG')) )
{
$is_jpeg = true;
}
}
}
else
{
switch($infoї2])
{
case 2:
case 9:
case 10:
case 11:
case 12:
$is_jpeg = true;
break;
default:
break;
}
}
if( $is_jpeg === false )
{
trigger_error('unknown file type supplied.', E_USER_ERROR);
}
}
else
{
trigger_error('an error occurred during upload: ' . intval($fileї'error']), E_USER_ERROR);
}
Posted: Mon Apr 04, 2005 11:11 am
by cs-web
How does that find if its a jpg if the function does not exist? The code is way to advanced for me to undertsand

Posted: Mon Apr 04, 2005 11:21 am
by feyd
if automatically fails due to
Posted: Tue Apr 05, 2005 4:02 am
by cs-web
No what I'm saying is id exif_imagetype isnt a function.. what method does it use to find it its a jpeg??
Posted: Tue Apr 05, 2005 9:56 am
by feyd
if getimagesize() failed, it attempts to use exif_imagetype().. if that doesn't exist, or fails in some fashion, the file is considered nonjpeg.
If you really really really want to make sure, you'll have to write a file signature checker, and verify the contents of the file.
There's only about 12 different variants of JPEG out there..
Posted: Tue Apr 05, 2005 4:00 pm
by cs-web
Well I know my host doesnt support those functionsIve tested both what can i do?
Posted: Tue Apr 05, 2005 5:33 pm
by feyd
your host doesn't support getimagesize() ? That's not apart of GD...
if you're absolutely sure, then you have to build a signature checker (at least).