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
snicolas
Forum Commoner
Posts: 97 Joined: Tue Nov 09, 2004 8:32 am
Post
by snicolas » Tue Jan 18, 2005 8:44 am
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jan 18, 2005 8:51 am
the answer varies from strpos()/substr() to using a regular expression, or even explode()
snicolas
Forum Commoner
Posts: 97 Joined: Tue Nov 09, 2004 8:32 am
Post
by snicolas » Tue Jan 18, 2005 9:07 am
thansk..but nmmmm not helpingmuch.,..
code example?
s
onion2k
Jedi Mod
Posts: 5263 Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com
Post
by onion2k » Tue Jan 18, 2005 9:16 am
$_FILES['whatever']['type'] .. much more reliable than trusting the filename.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jan 18, 2005 9:31 am
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
snicolas
Forum Commoner
Posts: 97 Joined: Tue Nov 09, 2004 8:32 am
Post
by snicolas » Tue Jan 18, 2005 9:46 am
onion2k answer was helpfull..thanks mate...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jan 18, 2005 9:50 am
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.