寫了一個簡單的html/php上傳的網頁,在安卓和電腦上都正常,但ipad上都有問題,即圖片上傳名稱都自動變成image.jpg

來源:互聯網
上載者:User
ipad的safari或chrome都是這樣的問題。

html
php// upload_file.php 0) {        // echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; 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;}?>

回複內容:

ipad的safari或chrome都是這樣的問題。

html
php// upload_file.php 0) {        // echo "Return Code: " . $_FILES["file"]["error"] . "
"; } else { echo "Upload: " . $_FILES["file"]["name"] . "
"; echo "Type: " . $_FILES["file"]["type"] . "
"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
"; 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;}?>

  1. 這就對了。ipad裡的照片根本就沒有“檔案名稱”這個概念。
  2. 隱藏檔時也不要檔案名稱一樣就丟棄啊……檔案儲存體又不是搶佔式的……
  3. 同名檔案加尾碼,或者乾脆整個檔案計算SHA-1後用校正值做檔案名稱。
  4. 判斷檔案類型不能依賴檔案的副檔名,而要使用exif_imagetype()函數檢查實際檔案頭。

請問這個問題怎麼解決的?我是蘋果手機上傳圖片名稱預設就改成了image.jpg. 我們用的是HTML5.安卓和瀏覽器上傳都正常。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.