我正在为允许 png、jpg、jpeg 和 gif 扩展名的用户运行图像上传脚本。
使用 IE 7-9 时,用户只能成功提交 png's 或 gif's。IE 用户似乎无法上传 jpg。
由于这个 IE 问题,我了解 pjpeg 并相应地修改了代码,但是问题仍然存在。IE 上的用户无法上传 jpg,但其他扩展程序工作正常。
有什么提示吗?谢谢!
PHP
$filename = basename($_FILES['photo']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
//Edit as per comments below
$ext = strtolower($ext);
//Check if the file is a JPG, JPEG, GIF or PNG image and it's size is less than 5Mb
$allowedExts = array('jpg', 'jpeg', 'gif', 'png');
if ( (in_array($ext, $allowedExts)) &&
($_FILES["photo"]["type"] == "image/jpeg") ||
($_FILES["photo"]["type"] == "image/png") ||
//Edit as per comments below
($_FILES["photo"]["type"] == "image/x-png") ||
($_FILES["photo"]["type"] == "image/gif") ||
($_FILES["photo"]["type"] == "image/pjpeg")
&& ($_FILES["photo"]["size"] <= 5242880) ){
//Name it and determine the path to which we want to save this file
$newname = str_replace( ' ', '_', trim( strip_tags( $_POST['first-name'].'_'.$_POST['last-name'] ) ) ) . '_' . $formKey->generateKey() . '_' . time() . '.jpg';
...
形式
<form id="submit-photo" action="index.php?p=uploader" enctype="multipart/form-data" method="POST">
<?php if(!isset($_SESSION['flash_message']) && isset($_SESSION['recent_field']) ) unset($_SESSION['recent_field']); ?>
<?php $formKey->outputKey(); ?>
<input type="hidden" name="MAX_FILE_SIZE" value="5242880" />
<div id="upload-photo">
<input type="file" name="photo" id="photo" />
</div>
...