简体   繁体   English

PHP - 如何从 getimagesize 而不是数字获取 mime 类型

[英]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.我正在使用 PHP 的getimagesize()函数从图像 URL 获取高度/宽度/类型。 Currently, for a jpg file, $type is returning 2 .目前,对于 jpg 文件, $type正在返回2 How can I get it to return the actual mime type instead?我怎样才能让它返回实际的 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;

This returns: Width: 640 Height: 360 Type: 2这将返回: Width: 640 Height: 360 Type: 2

Expected: Width: 640 Height: 360 Type: image/jpeg预期: 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'] .看起来您需要将整个返回值分配给局部变量(例如$size = getimagesize(...) ,然后从中获取 mime 类型,例如$size['mime']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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