check for jpg and gif without Zend?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Previously I was able to check for an uploaded file to be a jpg or a
gif by using the exif_imagetype() function.

I had to change from hosting provider and the new one doesn't want to
enable Zend on their php.

I would like to have a way to check for a file to be a jpg or gif file
in another way.

Is there anyone who can help me?

Best regards,


Re: check for jpg and gif without Zend?

<25 Nov 2006 09:54:57 -0800>

Quoted text here. Click to load it




print $logosize[2];



If it prints a 2 then its a .jpg file - cant remember what 0 , 1 , 3 ,  
etc stand for .

[0] is the width
[1] is the height
[2] is the image type
[3] is the width and height

<img src="<?php print $logo; ?>" width="<?php print $logosize[0]; ?>"  
height="<?php print $logosize[1]; ?>" border="0" alt="">

As your grabbing the image info anyway - its usually a good idea to use  
the width and height stuff as it saves the webpage from jumping all over  
the place .


Re: check for jpg and gif without Zend?

On Sat, 25 Nov 2006, Geoff wrote:

Quoted text here. Click to load it

I think so, I ran into the same problem, only in a different direction, I
had not attempted to upload files using PHP until recently.

I was uploading an image file to a filesystem whilst also entering the  
details of the upload into a database - these included FileName, FileSize  
and FileType - these were taken from $_FILES['upload']['name'],  
$_FILES['upload']['size'], $_FILES['upload']['type'] - GIF and JPG were  
represented as image/gif and image/jpeg as the types I uploaded, so I used  
the following:

$filetype = $_FILES['upload']['type'];

// upload was the name of the upload field in the previous form.

switch($filetype) {
case 'image/jpeg':
$extention = 'jpg';

case 'image/gif':
$extention = 'gif';

//( the reason for the switch is that I had a lot more image formats to  
sort through )

Sorry for the slightly longwinded answer - I was going mostly by memory.


Andy Grayndler

Site Timeline