Image Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Image Question

Post by icesolid »

I have a script that determines a file type and then it thumbnails the photo depending on the image type. Now all of my code is correct and works because on another server I use the exact same code and it works fine.

I get this error when using the exif_imagetype() function on this server:

Fatal error: Call to undefined function: exif_imagetype() in /home/caposcom/public_html/test.php on line 2

I tested to see if exif_imagetype() was the was the function causing the error above by using this code in a test file that nothing else in it but this code:

Code: Select all

<?php
if (exif_imagetype('/home/caposcom/public_html/photos/aerial.jpg') != IMAGETYPE_GIF) {
   echo 'The picture is not a gif';
}
?>
Does this host need to adjust something in their server? The host is peoplehost.com, thus far I am not satisfied this is my second problem with them.
User avatar
nickman013
Forum Regular
Posts: 764
Joined: Sun Aug 14, 2005 12:02 am
Location: Long Island, New York

Post by nickman013 »

The picture path does not have to be from the root. It has to be /path/to/file or http://www.site.com/path/to/file.jpg
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

I Know

Post by icesolid »

I understand that, however using photos/file.jpg or http://www.capo-us.com/photos/file.jpg or the root directory still gives me that error.

Anyone?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it would appear that you don't have the exif extension installed.. which is pretty often on hosts.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Really?

Post by icesolid »

HHM... thats weird, they should have it installed right?!??!

Anyways is there any other way to determine weither a image is .GIF or .JPG, thats all i need to determine.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Can't you use the file extension or do you have to read the image to check it?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

getimagesize(), which is a built-in function.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Huh?

Post by icesolid »

How does getimagesize() give me the image type?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

clearly sais how in the manual :wink:
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

if you just need to check extensions and you're not worried about malicious file uploads

Code: Select all

$file_ext = strtolower(strstr($_FILES['fieldname']['name'],"."));
that will return the exstension .gif .jpg .jpeg .tif etc
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

@scrotaye,
that's so not secure
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

scrotaye wrote:if you just need to check extensions and you're not worried about malicious file uploads
;)

depends on the purpose. if it's an admin section and he's going to be the only one uploading, then it wouldn't be a problem
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

scrotaye wrote:if you just need to check extensions and you're not worried about malicious file uploads

Code: Select all

$file_ext = strtolower(strstr($_FILES['fieldname']['name'],"."));
that will return the exstension .gif .jpg .jpeg .tif etc
The $_FILES array also gives you the MIME type .. easier than mucking about with the name. Though you need to remember FF and IE report different MIME types for certain images.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

...and you need to understand the inherant security issues with relying on that information. Which is VERY easy to fake.
icesolid
Forum Regular
Posts: 502
Joined: Mon May 06, 2002 9:36 pm
Location: Buffalo, NY

Question

Post by icesolid »

onion2k wrote:
scrotaye wrote:if you just need to check extensions and you're not worried about malicious file uploads

Code: Select all

$file_ext = strtolower(strstr($_FILES['fieldname']['name'],"."));
that will return the exstension .gif .jpg .jpeg .tif etc
The $_FILES array also gives you the MIME type .. easier than mucking about with the name. Though you need to remember FF and IE report different MIME types for certain images.
Does FF and IE report different MIME types for JPEG or GIF? because those are the only file types I am allowing to be uploaded.

The only file types allowed to be uploaded are JPEG or GIF so thats all I check for, if the file is not JPEG or GIF I send an error message saying NOT PROPER FILE TYPE.

And how do I use $_FILES[""] to pull out the MIME types?
Post Reply