I want get uploaded image extension.
As I know, best way is getimagesize()
function.
but this function's mime, returns image/jpeg
when image has .jpg
or also .JPEG
extension.
How can get exactly extension?
you can use php built-in pathinfo function. <? php $supported_image = array( 'gif', 'jpg', 'jpeg', 'png' ); $src_file_name = 'abskwlfd.
Click Image Downloader extension for Chrome saves you time by allowing you to save images with a keyboard shortcut. Simply hold the Shift key and right-click which saves you a wee bit of time. The extension works well with Google Images and Bing, but not with other websites.
To add the View Image extension, visit its page in the Chrome Web Store, click Add to Chrome, and then click Add extension in the following pop-up window. The View Image button should then show up in following Google Image searches.
you can use image_type_to_extension
function with image type returned by getimagesize
:
$info = getimagesize($path);
$extension = image_type_to_extension($info[2]);
$ext = pathinfo($filename, PATHINFO_EXTENSION);
You can also use strrpos and substr functions to get extension of any file
$filePath="images/ajax-loader.gif";
$type=substr($filePath,strrpos($filePath,'.')+1);
echo "file type=".$type;
output: gif
if you want extension like .gif
$type=substr($filePath,strrpos($filePath,'.')+0);
output: .gif
$image = explode(".","test.file.hhh.kkk.jpg");
echo end($image);
One more way to do it:
$ext = strrchr($filename, "."); // .jpg
$file_ext = pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION);
or to make it clean
$filename= $_FILES["file"]["name"];
$file_ext = pathinfo($filename,PATHINFO_EXTENSION);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With