在以下几行之后:
...
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
...
$this->load->library('upload', $config);
$this->upload->do_upload();
.bmp文件已成功上传到主机。但是,获取上传数据的宽度和高度将返回空值:
$imgdata = $this->upload->data();
print_r($imgdata);
也就是说,$imgdata['image_width']
和$imgdata['image_height']
根本没有任何价值。
我尝试上传其他图像文件类型,而不是bmp。它的高度和宽度都是有效数字。
为什么这只发生在.bmp图片上?我该如何解决这个问题?
编辑:
以下是$imgdata
上的print_r()
的内容;
[file_name] => 58ea3c1f14b45d7c1c2c0e0c1920af772b9ebf09.bmp
[file_type] => image/bmp
[file_path] => path/
[full_path] => path/58ea3c1f14b45d7c1c2c0e0c1920af772b9ebf09.bmp
[raw_name] => 58ea3c1f14b45d7c1c2c0e0c1920af772b9ebf09
[orig_name] => 58ea3c1f14b45d7c1c2c0e0c1920af772b9ebf09.bmp
[client_name] => samplebmp.bmp
[file_ext] => .bmp
[file_size] => 2484.45
[is_image] =>
[image_width] =>
[image_height] =>
[image_type] =>
[image_size_str] =>
为什么图像文件无法识别为图像?
答案 0 :(得分:2)
修改了system / libraries / Upload.php is_image()函数:
public function is_image()
{
// IE will sometimes return odd mime-types during upload, so here we just standardize all
// jpegs or pngs to the same file type.
$png_mimes = array('image/x-png');
$jpeg_mimes = array('image/jpg', 'image/jpe', 'image/jpeg', 'image/pjpeg');
$bmp_mimes = array('image/bmp');
if (in_array($this->file_type, $png_mimes))
{
$this->file_type = 'image/png';
}
if (in_array($this->file_type, $jpeg_mimes))
{
$this->file_type = 'image/jpeg';
}
if (in_array($this->file_type, $bmp_mimes))
{
$this->file_type = 'image/bmp';
}
$img_mimes = array(
'image/gif',
'image/jpeg',
'image/png',
'image/bmp'
);
return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE;
}
我添加了bmp mime类型,以便CI可以将.bmp识别为图像文件。请注意,我假设image / bmp是所有浏览器中返回的mime类型(我只在Firefox和Google Chrome中测试)。如果存在差异,请扩展类似于jpeg和png mimes的数组值。
修改后,$ imgdata ['image_width']和$ imgdata ['image_height']返回有效值。