How PHP Gets the file name extension
PHP get file extension There are many ways, the following provides three of the methods, you can study the next, specifically do not explain, directly to the final correct answer
echo pathinfo ('/www/htdocs/your_image.jpg ', pathinfo_extension);
Error wording:
You might write that.
function get_file_extension ($file _name) {
Return substr (STRRCHR ($file _name, '. '), 1);
}
or write like this
function File_extension ($filename) {
Return End (Explode (".", $filename));
}
By the way, what do you think pathinfo doing?
$file _path = pathinfo ('/www/htdocs/your_image.jpg ');
echo "$file _path [' dirname ']n ';
echo "$file _path [' basename ']n ';
echo "$file _path [' extension ']n ';
echo "$file _path [' filename ']n '; Only in PHP 5.2+
?>
The above will output
/www/htdocs
Your_image.jpg
Jpg
Your_image
, the code is as follows:
Method One
function Extend_1 ($file _name)
{
$retval = "";
$pt =strrpos ($file _name, ".");
if ($pt) $retval =substr ($file _name, $pt +1, strlen ($file _name)-$pt);
return ($retval);
}
Method Two
function Extend_2 ($file _name)
{
$extend = PathInfo ($file _name);
$extend = Strtolower ($extend ["extension"]);
return $extend;
}
Method Three
function Extend_3 ($file _name)
{
$extend =explode (".", $file _name);
$va =count ($extend)-1;
return $extend [$va];
}
?>
http://www.bkjia.com/PHPjc/632277.html www.bkjia.com true http://www.bkjia.com/PHPjc/632277.html techarticle php Get file extension method php get file extension There are many ways, the following provides three of the methods, you can study the next, specifically do not explain, directly to the final positive ...