Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
Moderator: General Moderators
cs-web
Forum Commoner
Posts: 27 Joined: Fri Mar 11, 2005 11:57 am
Post
by cs-web » Mon Apr 04, 2005 10:17 am
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']);
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Apr 04, 2005 10:43 am
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);
}
cs-web
Forum Commoner
Posts: 27 Joined: Fri Mar 11, 2005 11:57 am
Post
by cs-web » Mon Apr 04, 2005 11:11 am
How does that find if its a jpg if the function does not exist? The code is way to advanced for me to undertsand
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Apr 04, 2005 11:21 am
if automatically fails due to
cs-web
Forum Commoner
Posts: 27 Joined: Fri Mar 11, 2005 11:57 am
Post
by cs-web » Tue Apr 05, 2005 4:02 am
No what I'm saying is id exif_imagetype isnt a function.. what method does it use to find it its a jpeg??
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Apr 05, 2005 9:56 am
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..
cs-web
Forum Commoner
Posts: 27 Joined: Fri Mar 11, 2005 11:57 am
Post
by cs-web » Tue Apr 05, 2005 4:00 pm
Well I know my host doesnt support those functionsIve tested both what can i do?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Apr 05, 2005 5:33 pm
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).