PHP supports file uploads. user can design a system where he can allow users to upload files with specific extension type.
In many website we have the provision to upload files with specific file extension.
For example facebook we can upload file with extension jpeg, jpg,png etc for the profile picture.
Similarly it can be achieved in PHP. Following function returns you the extension of the given file type.
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$filename = "images/image01.jpeg" ;
$extension=getExtension($filename);
echo "Extension of the file is: ".$extension;
The output of the above function call will be:
Extension of the file is: jpeg
In many website we have the provision to upload files with specific file extension.
For example facebook we can upload file with extension jpeg, jpg,png etc for the profile picture.
Similarly it can be achieved in PHP. Following function returns you the extension of the given file type.
function getExtension($str)
{
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$filename = "images/image01.jpeg" ;
$extension=getExtension($filename);
echo "Extension of the file is: ".$extension;
The output of the above function call will be:
Extension of the file is: jpeg
No comments:
Post a Comment