get extension of a file

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, "."); ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-14-2007
VooDoo
 
Posts: n/a
Default get extension of a file

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



Reply With Quote
  #2 (permalink)  
Old 12-14-2007
Rik Wasmus
 
Posts: n/a
Default Re: get extension of a file

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
Reply With Quote
  #3 (permalink)  
Old 12-14-2007
Michael Fesser
 
Posts: n/a
Default Re: get extension of a file

..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
Reply With Quote
  #4 (permalink)  
Old 12-14-2007
Rik Wasmus
 
Posts: n/a
Default Re: get extension of a file

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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:17 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0