2012-04-20 49 views
0

我有此功能檢查,如果該文件是一個圖像或不是,但它始終返回false無法檢查該文件的類型被上傳

function upload_file($file) { 
    if($file['type'] != "image/jpeg" || $file['type'] != "image/gif") { 
         $errors[] = "Please upload a photograph with extenstion of JPEG, JPG, GIF or BMP."; 
         return false; 
    } 
} 

所以誰能告訴我在哪裏出了錯這裏!

在此先感謝。

回答

1

您需要使用&&

if($file['type'] != "image/jpeg" && $file['type'] != "image/gif") { 

使用||你使它自始至終都是假的o圖像可以是一個jpeg和一個gif

+0

非常感謝你真的保存了一天 – 2012-04-21 00:09:57

0
if($file['type'] != "image/jpeg" || $file['type'] != "image/gif") { 

應該

if($file['type'] !== "image/jpeg" || $file['type'] !== "image/gif") { 

編輯:沒關係,這並不重要

+0

其實只是廣告類型比較支票這不是一個問題在這裏 – 2012-04-20 18:51:30

+0

你是對的,沒有意識到 – squarephoenix 2012-04-20 18:52:19