Rumah > Artikel > pembangunan bahagian belakang > 写了一个简单的html/php上传的网页,在安卓和电脑上都正常,但ipad上都有问题,即图片上传名称都自动变成image.jpg
ipad的safari或chrome都是这样的问题。
<code>html</code><code><!--表单--> <div 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> </div> </code>
<code>php</code><code>// 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; } ?> </code>
ipad的safari或chrome都是这样的问题。
<code>html</code><code><!--表单--> <div 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> </div> </code>
<code>php</code><code>// 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; } ?> </code>
exif_imagetype()
函数检查实际文件头。
请问这个问题怎么解决的?我是苹果手机上传图片名称默认就改成了image.jpg. 我们用的是HTML5.安卓和浏览器上传都正常。