PHP - 如何从 getimagesize 而不是数字获取 mime 类型
PHP - how to get mime type from getimagesize instead of a number
我正在使用 PHP 的 getimagesize() 函数从图像 URL 中获取 height/width/type。当前,对于 jpg 文件,$type
是 returning 2
。我怎样才能将它改为 return 实际的 MIME 类型?
<?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;
这个 returns: Width: 640 Height: 360 Type: 2
预计:Width: 640 Height: 360 Type: image/jpeg
documentation 很清楚 return 的功能是什么。看起来您需要将整个 return 值分配给局部变量(例如 $size = getimagesize(...)
,然后从中获取 mime 类型,例如 $size['mime']
。
我正在使用 PHP 的 getimagesize() 函数从图像 URL 中获取 height/width/type。当前,对于 jpg 文件,$type
是 returning 2
。我怎样才能将它改为 return 实际的 MIME 类型?
<?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;
这个 returns: Width: 640 Height: 360 Type: 2
预计:Width: 640 Height: 360 Type: image/jpeg
documentation 很清楚 return 的功能是什么。看起来您需要将整个 return 值分配给局部变量(例如 $size = getimagesize(...)
,然后从中获取 mime 类型,例如 $size['mime']
。