By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

get extension of a file

P: n/a
Hi all,
I used to use this for getting the extension of an uploaded file..
$ext = strstr($doc, ".");

but apparently this not work when the filename contain a '.'

What is the best way to get the correct extension of a file???
Thanks for your suggestion.
VooDoo

Dec 14 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Fri, 14 Dec 2007 14:38:41 +0100, VooDoo <Vo*********@free.frwrote:
Hi all,
I used to use this for getting the extension of an uploaded file..
$ext = strstr($doc, ".");

but apparently this not work when the filename contain a '.'

What is the best way to get the correct extension of a file???
Thanks for your suggestion.
preg_match('/\.([^.]+)$/',$string,$match);
or
strrchr($string,'.');
--
Rik Wasmus
Dec 14 '07 #2

P: n/a
..oO(VooDoo)
>Hi all,
I used to use this for getting the extension of an uploaded file..
$ext = strstr($doc, ".");

but apparently this not work when the filename contain a '.'

What is the best way to get the correct extension of a file???
$ext = pathinfo($doc, PATHINFO_EXTENSION);

Micha
Dec 14 '07 #3

P: n/a
On Fri, 14 Dec 2007 19:18:41 +0100, Michael Fesser <ne*****@gmx.dewrote:
.oO(VooDoo)
>Hi all,
I used to use this for getting the extension of an uploaded file..
$ext = strstr($doc, ".");

but apparently this not work when the filename contain a '.'

What is the best way to get the correct extension of a file???

$ext = pathinfo($doc, PATHINFO_EXTENSION);
Ah, that's what I was looking for, thank you. Kept ending up in the finfo*
functions for some reason (which are commonly more usefull then extensions
offcourse).
--
Rik Wasmus
Dec 14 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.