我现在已经尝试了几次,这是我认为我能让它正常工作的最接近的。我在其他地方有类似的代码并且它正常工作但是当我执行这个时,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 :(得分: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 );