[SOLVED] File Extension

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

Post Reply
User avatar
kevin_javia
Forum Newbie
Posts: 15
Joined: Mon May 24, 2004 9:46 am
Location: India
Contact:

File Extension

Post by kevin_javia »

Hi there,

How can I extract the file extension of the file?

I came across mime_content_type() but it gives only file type not file extension.

Can any one help me?

Thanks a ton in advance.

Kevin.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Explode the file name by "." and then take the last element of the array you produce:

Code: Select all

$filename = "hello.rar";
$x = explode(".", $filename);
$x = array_reverse($x);
echo $x; #echos "rar";

$filename = "hello.world.text.edited.txt";
$x = explode(".", $filename);
$x = array_reverse($x);
echo $x; #echos "txt";
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

this was posted not too long ago...

Also, you might want to try out the forum's search

Could save some time, and typing!
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Im surprised that there isnt a function in php to get the extension though.

(WOOHOOOO 400!!!!!!!!)
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Yeah, that'd be really helpful!

happy 400th! 8)
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Thanks - only 100 more till im a master.....i best start posting!!

</end of rant>
User avatar
kevin_javia
Forum Newbie
Posts: 15
Joined: Mon May 24, 2004 9:46 am
Location: India
Contact:

File Extension [SOLVED]

Post by kevin_javia »

Thanks a lot.

Kevin.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

No Problem! This is waht we are here for8)

Also, Instead of putting "[SOLVED]" in the reply subject, edit you original post and add "[SOLVED]" to that subject!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

or you can wait for a mod to just mark it solved.. ;)
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

If only i were a mod.... :roll:
Post Reply