2017-06-26 210 views
0

我已經嘗試了幾次現在,這是最接近,我想我得到它正常工作。我在其他地方有類似的代碼,它工作正常,但是當我執行這個時,mime_content_type不會返回任何東西。我試圖用很多不同的方式讓它工作,讓我知道你是否看到我忽略的東西。PHP mime_content_type沒有返回任何東西

for($i = 0; $i < 5; ++ $i) { 

       $mime = false; 

       if (preg_match ('/(jpeg|png|gif|jpg|jpe)/i', $_FILES ['listing'] ['type'] ['images'] [$i])) { 

        $new_image = new image_handler ($_FILES ['listing'] ['tmp_name'] ['images'] [$i]); 

        $m = mime_content_type ($new_image); 

        if ($m == 'image/png' || $m == 'image/jpeg' || $m == 'image/gif') { 
         $mime = true; 
        } 

        if ($mime) { 
         $new_images [$i] ['name'] = date ('ymdgis') . $_FILES ['listing'] ['name'] ['images'] [$i]; 
         $new_images [$i] ['default'] = ($_POST ['listing'] ['default_image'] == $i) ? true : false; 

         $new_image->save (IMAGE_SIZE, IMAGE_SIZE, REAL_PATH . 'uploads/listings/' . $new_images [$i] ['name']); 
         $new_image->save (THUMB_SIZE, THUMB_SIZE, REAL_PATH . 'uploads/listings/thumbnails/' . $new_images [$i] ['name']); 
        } 
       } elseif ((! preg_match ('/(jpeg|png|gif|jpg|jpe)/i', $_FILES ['listing'] ['type'] ['images'] [$i])) && ($_FILES ['listing'] ['name'] ['images'] [$i] != '')) { 
        $pass_message .= '<p>The File ' . $_FILES ['listing'] ['name'] ['images'] [$i] . ' was not uploaded due to its filetype.</p>'; 
       } 
       if (! $mime && ($_FILES ['listing'] ['name'] ['images'] [$i] != '')) { 
        $pass_message .= '<p>The File ' . /*$_FILES ['uploads'] ['name'] ['image']*/ $m . ' was not uploaded due to its mime type.</p>'; 
       } 
      } 

回答

0

根據文檔,mime_content_type將文件名作爲輸入參數。

在您的示例中,您正在實例化傳遞到mime_content_type()函數的新image_handler()對象。

我相信你應該在你的課堂上有一個方法來獲取文件路徑。

事情是這樣的:

$new_image = new image_handler ($_FILES ['listing'] ['tmp_name'] ['images'] [$i]); 
$filename = $new_image->get_filename_method(); 

$m = mime_content_type ($filename);