0
我的系统上保存了一些没有文件扩展名的图像,它们以“FILENAME”格式显示。 (注意期间)确定缺少扩展名的图像的文件扩展名
我想使用getimagesize();但示数出来告诉我,“文件名不能为空”
下面是代码的样本我使用
$contents = file_get_contents($localFile);
$imageData = getimagesize($contents);
// $imageData[2] will contain the value of one of the constants
$mimeType = image_type_to_mime_type($imageData[2]);
$extension = image_type_to_extension($imageData[2]);
你的图像应该有扩展名(例如GIF,JPG,PNG等)。并非所有浏览器都可能将MIME类型返回到PHP脚本,因此您最好创建一个允许的扩展数组(例如$ allowedExts = array('jpg','gif','png')),然后展开图像的文件名(例如$ tmp = explode(“。”,$ filename)),并使用'in_array($ tmp,$ allowedExts)'检查上传的文件是否为图像。如果是这样,那么做任何你想要的。 – Bob