2014-01-18 20 views
1

如何使這個exif_imagetype()函數變爲caseinsensitive?這樣它會同時允許.jpg和.JPG?不能想出這一個。ive嘗試與stripos();沒有運氣。這裏是我的代碼:WITH用strtolower將exif_imagetype變爲caseinsensitive?

$allowed_types = array(IMAGETYPE_GIF,IMAGETYPE_JPEG,IMAGETYPE_PNG); 
    if (in_array(exif_imagetype($_FILES["uploaded_file"]["tmp_name"]), $allowed_types)){ 

     // SUCCSESFUL 

得到錯誤()

$allowed_types = array(IMAGETYPE_GIF,IMAGETYPE_JPEG,IMAGETYPE_PNG); 
    if (strtolower(in_array(exif_imagetype($_FILES["uploaded_file"]["tmp_name"]), $allowed_types))){ 

它說: 「:)exif_imagetype(:警告文件名不能爲空」

編輯:我只有當我嘗試上傳大寫.JPG圖片時得到這個錯誤..大多數現代相機使用這種格式,這是很煩人,如果你問我:D很多網站是因此,失去用戶,我們必須找到解決這個問題的方法。

回答

2

只要在您接受的所有輸入中將strtolower()輸入到您的「tmp name」變量中,然後執行strtolower()。你應該在輸入的某個地方清理輸入,所以你也要這樣做。

+0

@殭屍,它顯示了同樣的上述錯誤^^無論在哪裏我把strotolower()或stripos函數()......除此之外,我的代碼工作正常,我只得到這錯誤,當我上傳的文件的擴展名爲.JPG .. wierd? – user3103188

0

使用:

$allowed_types = array(strtolower(IMAGETYPE_GIF),strtolower(IMAGETYPE_JPEG),strtolower(IMAGETYPE_PNG)); 
if (in_array(strtolower(exif_imagetype($_FILES["uploaded_file"]["tmp_name"])), $allowed_types)){ 
+0

@ Poostchi,這劑量解決了這個問題。我得到了上面的錯誤^^不管我在哪裏把strtolower()或stripos()..即使沒有它。只有當我嘗試上傳大多數相機今天使用的大寫.JPG文件時:P – user3103188

+0

您也應該使用小寫字母表示允許的類型。嘗試編輯答案。 – poostchi

+0

複製!只是爲了確保我正確理解你..我應該刪除我的「if(in_array(」和只寫「strtolower(exif_imagetype($ _ FILES [」uploaded_file「] [」tmp_name「]);」或你在說什麼? – user3103188