Page 1 of 1
get image extension from file uplaod
Posted: Tue Jan 18, 2005 8:44 am
by snicolas
Hi,
I am uploading images using a simple file uplaod form.
How do I get the extension of this image to check if the extension is correct or not?
s
Posted: Tue Jan 18, 2005 8:51 am
by feyd
the answer varies from strpos()/substr() to using a regular expression, or even explode()
Posted: Tue Jan 18, 2005 9:07 am
by snicolas
thansk..but nmmmm not helpingmuch.,..
code example?
s
Posted: Tue Jan 18, 2005 9:16 am
by onion2k
$_FILES['whatever']['type'] .. much more reliable than trusting the filename.
Posted: Tue Jan 18, 2005 9:31 am
by feyd
the 'type' is arbitrary, as the browser may think it's something else. Same with the extension.. which is probably more easily changed.
The "best" thing to do is know the file format specification of the files you wish to accept, and be able to analyze the files' contents
Posted: Tue Jan 18, 2005 9:46 am
by snicolas
onion2k answer was helpfull..thanks mate...
Posted: Tue Jan 18, 2005 9:50 am
by feyd
since you are wanting to upload images, I'd suggest using
getimagesize()
as that will actually analyze the file for it's type, instead of just looking at the extension.