This is a discussion on get extension of a file within the PHP Language forums, part of the PHP Programming Forums category; Hi all, I used to use this for getting the extension of an uploaded file.. $ext = strstr($doc, "."); ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
On Fri, 14 Dec 2007 14:38:41 +0100, VooDoo <VooDooNet38@free.fr> wrote:
> 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 |
|
|||
|
..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 |
|
|||
|
On Fri, 14 Dec 2007 19:18:41 +0100, Michael Fesser <netizen@gmx.de> wrote:
> .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 |