gpt4 book ai didi

PHP- 通过 URL 获取文件类型

转载 作者:可可西里 更新时间:2023-11-01 13:11:07 26 4
gpt4 key购买 nike

我想使用 PHP 通过 URL 获取文件类型(例如 image/gif)。我试过

<?php
$image_path="http://fc04.deviantart.net/fs71/f/2010/227/4/6/PNG_Test_by_Destron23.png";
exif_imagetype($image_path);
?>

上面的代码给了我一个空白页,下面的代码返回了“3”:

<?php
$image_path="http://fc04.deviantart.net/fs71/f/2010/227/4/6/PNG_Test_by_Destron23.png";
echo exif_imagetype($image_path);
?>

我哪里错了?已解决:使用 Fileinfo 获取内容类型

最佳答案

这是我想出的一个 PHP 函数:

/**
* @param $image_path
* @return bool|mixed
*/
function get_image_mime_type($image_path)
{
$mimes = array(
IMAGETYPE_GIF => "image/gif",
IMAGETYPE_JPEG => "image/jpg",
IMAGETYPE_PNG => "image/png",
IMAGETYPE_SWF => "image/swf",
IMAGETYPE_PSD => "image/psd",
IMAGETYPE_BMP => "image/bmp",
IMAGETYPE_TIFF_II => "image/tiff",
IMAGETYPE_TIFF_MM => "image/tiff",
IMAGETYPE_JPC => "image/jpc",
IMAGETYPE_JP2 => "image/jp2",
IMAGETYPE_JPX => "image/jpx",
IMAGETYPE_JB2 => "image/jb2",
IMAGETYPE_SWC => "image/swc",
IMAGETYPE_IFF => "image/iff",
IMAGETYPE_WBMP => "image/wbmp",
IMAGETYPE_XBM => "image/xbm",
IMAGETYPE_ICO => "image/ico");

if (($image_type = exif_imagetype($image_path))
&& (array_key_exists($image_type ,$mimes)))
{
return $mimes[$image_type];
}
else
{
return FALSE;
}
}

关于PHP- 通过 URL 获取文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25918761/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com