简体   繁体   中英

PHP - how to get mime type from getimagesize instead of a number

I am using PHP's getimagesize() function to get the height/width/type from an image URL. Currently, for a jpg file, $type is returning 2 . How can I get it to return the actual mime type instead?

<?php
    list($width, $height, $type) = getimagesize('https://loremflickr.com/cache/resized/65535_51564349748_2ceac19a11_z_640_360_nofilter.jpg');
    echo 'Width: ' . $width . ' Height: ' . $height . ' Type: ' . $type;

This returns: Width: 640 Height: 360 Type: 2

Expected: Width: 640 Height: 360 Type: image/jpeg

The documentation is pretty clear about what the function returns. Looks like you need to assign the entire return value into a local variable (eg $size = getimagesize(...) , and then get the mime type from that like $size['mime'] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM