2017-07-02 59 views
0

我試着上傳.png文件與我的圖片上傳功能。有些圖像可以工作,例如this one。但由於某些原因,使用Windows快照工具捕獲的.png圖像不起作用。不能上傳一些.png文件

我得到的錯誤信息是:「對不起,只有JPG,JPEG,PNG & GIF文件是允許的。」,當然還有「對不起,您的文件沒有上傳」。 (見下面的代碼)。

我確定我用Windows快照工具生成的是.png圖片,爲什麼我的代碼不能接受它們?

<?php 
    $target_dir = "i/"; 
    $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 
    $uploadOk = 1; 
    $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
    // Check if image file is a actual image or fake image 
    if(isset($_POST["imgUpload"])) { 
     $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); 
     if($check !== false) { 
      $uploadOk = 1; 
     } else { 
      echo "File is not an image.<br>"; 
      $uploadOk = 0; 
     } 
     // Check if file already exists 
     if (file_exists($target_file)) { 
      echo "Sorry, file already exists.<br>"; 
      $uploadOk = 0; 
     } 
     // Check file size 
     if ($_FILES["fileToUpload"]["size"] > 5000000) { 
      echo "Sorry, your file is too large.<br>"; 
      $uploadOk = 0; 
     } 
     // Allow certain file formats 
     if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" 
     && $imageFileType != "gif") { 
      echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.<br>"; 
      $uploadOk = 0; 
     } 
     // Check if $uploadOk is set to 0 by an error 
     if ($uploadOk == 0) { 
      echo "Sorry, your file was not uploaded.<br>"; 
     // if everything is ok, try to upload file 
     } else { 
      $path_parts = pathinfo($target_file); 
      $tmpFileName = round(microtime(true)); 
      $newfilename = $tmpFileName . '.' . $path_parts['extension']; 

//Et cetera et cetera 

我已經基於我的上傳代碼幾乎完全是W3C's示例。 任何人都可以解釋這個問題嗎?

+1

我的心理調試技巧告訴我,你的問題是'「PNG」!=「PNG」'。 – SLaks

+0

哦..不知道這件事。我會嘗試一下。爲什麼有些圖像PNG和其他只是PNG呢? –

+0

基督,工作。這個男孩很尷尬。你真的是心靈的。 .gif和.GIF等類似嗎? –

回答

0

擴展可以有任何情況。

你需要區分大小寫的比較。