2011-09-03 66 views
0

我目前在上傳腳本時遇到了一些問題。 它不檢查文件類型是否允許,我不明白爲什麼。 有沒有人看到我的問題?PHP:圖像檢查擴展

   //Reads the image name 
      $image=$_FILES['image']['name']; 

      //If empty 
      if ($image == "") { 
      echo '<div class="box_square form_error" style="margin-bottom:15px; padding:10px; font-size:11px;">Velg et bilde!</div>'; 
      $errors = 1; 
      } 

      //If not empty 
      if ($image) 
      { 
       //Get orgiginal name from client machine 
       $filename = stripslashes($_FILES['image']['name']); 
       //Get the extension 
       $extension = getExtension($filename); 
       $extension = strtolower($extension); 

       //If file extension not known, error. If not, continue 
       if (($extension != "jpg") && ($extension != "jpeg")) 
       { 
        //Error message 
        echo '<div class="box_square form_error" style="margin-bottom:15px; padding:10px; font-size:11px;">Bare JPG og JPEG er tilatte filtyper!</div>'; 
        $errors = 1; 

       } 
+0

發生了什麼,你不想發生? –

+0

當文件類型未知時,它不會回顯消息。 – Kaizokupuffball

+0

那麼,'$ extension'包含了什麼? –

回答

0

它看起來像一個不正確的getExtension($文件名)。但是,我不知道你爲什麼使用反斜槓。

如何

echo "the extension used is ".$extension."<br>"; 

$extension = strtolower($extension); 

順便說一句,您使用表達式規則

preg_match("/\.([^\.]+)$/", $filename, $extension); 
+0

那也沒有輸出任何東西。 – Kaizokupuffball

0

不靠延長,但是,mime type,而不是可以提取擴展。

+1

....如果有人將'hack.php'上傳爲'image/jpeg',則發佈日期? – Jonathon

+0

傑尼傑尼!必須檢查他們兩個。 – Charlie

+0

你最好在服務器上檢查MIME類型,不要相信瀏覽器發送給你的東西。但是,檢查文件擴展名不會有幫助。您的服務器可能會以某種方式解析許多文件擴展名(例如,php,phtml,php3,php4,php5,py,...)。 – str