[SOLVED] Getting a file extension
Moderator: General Moderators
-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
[SOLVED] Getting a file extension
Is there a way to get the file extension of an image, because I want different code to be used whether the file is a .gif, .jpg or a .png?
I have been looking at 'image_type_to_extension' but I dont think this is the right thing.
Cheers in advance
I have been looking at 'image_type_to_extension' but I dont think this is the right thing.
Cheers in advance
Last edited by rubberjohn on Wed Mar 02, 2005 5:59 am, edited 1 time in total.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Personally I would use:
http://www.php.net/manual/en/function.m ... t-type.php
I don't like relying on a filename, I like to check the file contents itself.
http://www.php.net/manual/en/function.m ... t-type.php
I don't like relying on a filename, I like to check the file contents itself.
-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
thats the one
cheers thats just what I needed
-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
Sorry one last thing
When it returns:
image/gif
how can i split the string using the ' / ' as the marker to split the first part ' image ' into a variable and the second bit 'gif' into a variable.
This really is the last bit now
Cheers
image/gif
how can i split the string using the ' / ' as the marker to split the first part ' image ' into a variable and the second bit 'gif' into a variable.
This really is the last bit now
Cheers
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
use explode() function.
Last edited by n00b Saibot on Wed Mar 02, 2005 10:14 am, edited 1 time in total.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
-
rubberjohn
- Forum Contributor
- Posts: 193
- Joined: Fri Feb 25, 2005 4:03 am
Thats really it now
cheers for your help thats got it working now
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
if I'm expecting an image, I use getimagesize()
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
mime-content-type cannot be fooled either as it checks the file contents. It has the advantage that it doesn't matter if the file is not an image. The same methodology can therefore be used for any upload.pickle wrote:getimagesize() doesn't rely on the extension, so it can't be spoofed with someone just putting a funky extension on a file.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
uh..CoderGoblin wrote:mime-content-type cannot be fooled either as it checks the file contents. It has the advantage that it doesn't matter if the file is not an image. The same methodology can therefore be used for any upload.
mime_content_type wrote: Returns the MIME content type for a file as determined by using information from the magic.mime file. Content types are returned in MIME format, like text/plain or application/octet-stream.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany