Page 1 of 1

How to get the extension of a filename...

Posted: Thu Sep 17, 2009 2:04 am
by revbackup
hi guys,


I have a problem with getting the extension of a filename...

at first what i did is to do like this

Code: Select all

 
$file = hello.php; 
$ext= explode('.',$file);
//so i get $ext[1] which is .php
 
but i have a problem when the filename has a name like this:

$file = hello.cfg.inc.php;

with my code, i can get cfg instead of the php that i want to get....

So, how can i get the real file extension of a file?
thanks...

Re: How to get the extension of a filename...

Posted: Thu Sep 17, 2009 2:13 am
by dude81

Re: How to get the extension of a filename...

Posted: Thu Sep 17, 2009 2:34 am
by revbackup
I cannot use $_FILE because my file is from a server so I need to use
ftp functions...

and filetype is not available in ftp functions..

so i have to use string functions to get the file extensions of the file...

Re: How to get the extension of a filename...

Posted: Thu Sep 17, 2009 4:52 am
by Mark Baker
$extension = pathinfo($filename,PATHINFO_EXTENSION);