我遇到了一个非常有趣的问题。我在下面写的脚本可以工作,但在Internet Explorer中不起作用。MAX_WIDTH变量设置为450,它仍然以图像的原始尺寸上传图像,而不是以任何转换因子为450。有什么建议吗?它可以在Chrome、Firefox和Safari中工作并调整大小。此外,我正在测试的IE版本是IE 8 64位版本。谢谢
private function checkForResize() {
$fileTypeArray = array('image/gif', 'image/jpeg', 'image/png');
$origType = $this->_uploadType;
if (in_array($origType, $fileTypeArray)) {
$origImage = $_FILES[$this->_uploadInputField]['tmp_name'];
$imageWidth = getimagesize($origImage);
if ($imageWidth[0] > MAX_WIDTH) {
// Resize here
if ($origType == 'image/gif') {
$imageSrc = imagecreatefromgif($origImage);
} else if ($origType == 'image/jpeg') {
$imageSrc = imagecreatefromjpeg($origImage);
} else if ($origType == 'image/png') {
$imageSrc = imagecreatefrompng($origImage);
} else {
return false;
}
$width = $imageWidth[0];
$height = $imageWidth[1];
$newHeight = ($height / $width) * MAX_WIDTH;
$tmpImage = imagecreatetruecolor(MAX_WIDTH, $newHeight);
$this->setTransparency($tmpImage, $imageSrc);
imagecopyresampled($tmpImage, $imageSrc, 0, 0, 0, 0, MAX_WIDTH, $newHeight, $width, $height);
imagejpeg($tmpImage, UPLOAD_DIR.DS.$this->_uploadSafeName, 100);
imagedestroy($imageSrc);
imagedestroy($tmpImage);
return true;
}
}
return false;
}
将我的评论转换为答案:
浏览器与服务器端脚本出错无关,因为它在客户端。
然而,可能的错误是MIME类型是一个不可靠的信息,因为是浏览器检测并发送MIME类型。
在处理jpgs或pngs时,IE有时会发送image/pjpeg
或image/x-png
MIME类型,因此在验证时也需要检查这些类型。