This post explains about how to get file extenstion using the php. In the we have two types to retrieve the file extensions.

How to get file extension using PHP by Anil Kumar Panigrahi
See the following script :
Type 1:
<?php
function findextension ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
$filename="image.jpg";
echo findextension ($filename);
// Here we will get the file extension
$filename="image.jpg";
echo findextension ($filename);
// Here we will get the file extenstion
?>
function findextension ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
$filename="image.jpg";
echo findextension ($filename);
// Here we will get the file extension
$filename="image.jpg";
echo findextension ($filename);
// Here we will get the file extenstion
?>
Type 2:
Another way to get file extension:
<?php
function file_extension($filename)
{
return end(explode(".", $filename));
}
echo file_extension("anil.labs.jpg");
?>
function file_extension($filename)
{
return end(explode(".", $filename));
}
echo file_extension("anil.labs.jpg");
?>
Thanks,
Anil Kumar Panigrahi
Can u help me.
how to redirect URL’s using .htaccess file
like this
http://domain.com/index.php?id=srinivas&page=2
to
http://domain.com/srinivas?page=2
Pingback : How to download a file using php code - Anil Labs
more simpler:
strtolower(end(explode(‘.’,$filename));
also worth reading http://php.net/manual/en/function.pathinfo.php
Pingback : Code snippets of PHP and Javascript - Anil Labs