ipad的safari或chrome都是这样的问题。
html
<!--表单--> <p id="upload"> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </p>
php
// upload_file.php <?php error_reporting(E_ERROR| E_PARSE); session_start(); $name=$_SESSION["free_print_name"]; $phone=$_SESSION["free_print_phone"]; if (!file_exists("/var/www/upload_files/".$phone)) { mkdir("/var/www/upload_files/".$phone); } $DIR="/var/www/upload_files/".$phone."/"; $temp_array=explode('.', $_FILES["file"]["name"]); $postfix=$temp_array[count($temp_array)-1]; if ( ($postfix=="pdf" || $postfix == "doc" || $postfix == "docx" || $postfix == "rtf" || $postfix == "ppt" || $postfix == "jpg" || $postfix == "jpeg" || $postfix == "png" || $postfix == "psd") && ($_FILES["file"]["size"] < 20000000)) { if ($_FILES["file"]["error"] > 0) { // echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists($DIR . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; header('Location: http://59.78.7.9/index.html'); } else { move_uploaded_file($_FILES["file"]["tmp_name"], $DIR. $_FILES["file"]["name"]); echo "Stored in: " . $DIR . $_FILES["file"]["name"]; header('Location: http://59.78.7.9/index.html'); } } } else { echo "Invalid file, you can't upload files of ".$postfix; } ?>
PHP中文网2017-04-10 15:14:17
exif_imagetype()
函数检查实际文件头。伊谢尔伦2017-04-10 15:14:17
请问这个问题怎么解决的?我是苹果手机上传图片名称默认就改成了image.jpg. 我们用的是HTML5.安卓和浏览器上传都正常。
<input type="file" onchange="uploadonchange(this)" name="file" class="input" id="file-upload" accept="image/*">