Page 1 of 1

Mime Type

Posted: Sat Apr 19, 2003 2:44 am
by leinad256
I tried, I looked and I almost died...but I couldnt find it.

I need to know if a file is jpg, but looking the extension isnt enough and I cant use the mime_content_type function because I have php 4.2 and this function is avaible until php 4.3.

Its not a email attachment or upload file, then the $_FILE (or the array where it contains the uploaded file...I forgot the name) doesnt work me.

Some ideas???

I will be glad you if you can help

thx everybody

Posted: Sat Apr 19, 2003 9:09 am
by volka
if your script is running on a unix-system you might use file with php's exec functions

Posted: Sat Apr 19, 2003 10:22 am
by pootergeist
getimagesize -- second indices return

example
$a = getimagesize($_FILES['fieldname']['tmp_name']);
if($a[2] !== 2) { // not a valid jpeg file }

$a[2] would return 1 = gif, 2 = jpeg, 3 = png, 4 = swf.......

Posted: Sat Apr 19, 2003 11:44 am
by leinad256
Thanks by your answers, I have a Mac OS X and it is a UNIX based System, maybe it will work. The getimagesize function doesnt work me because if the file isnt a image the php send me a error.


Thxxxxx


Best Regards from Mexico

Posted: Sat Apr 19, 2003 12:20 pm
by leinad256
Sorry, I dont kwon which exec function I need. I tried to look the mime type with the file function but it return me a lot of unreable code. Can you give me more details???


Thx man

Posted: Sat Apr 19, 2003 12:39 pm
by volka
I think for separating jpegs from non-jepgs pootergeist's suggestion is better.
What exactly is the error you get?
to avoid a warning that might be printed (undefined index 2 in $a) try

Code: Select all

<?php
$fileToCheck = 'notAJpeg.dat';
$a = @getimagesize($fileToCheck);
if (count($a) < 1 || $a[2] != 2)
	echo 'not a jpeg';
else
	echo 'all right';
?>

Posted: Sat Apr 19, 2003 1:39 pm
by leinad256
thats right!!!!!!!!

I didnt realize about the @ operator



thx very much!!!!!!!!!!!!!!!!!!!!!!

when u come to mexico i gonna invite u some tequilas :D



thx volka, thx pootergeist