使用CodeIgniter的上载库0的宽度和高度上载.bmp图像 [英] Uploading .bmp image using CodeIgniter's upload library 0 width and height

查看:68
本文介绍了使用CodeIgniter的上载库0的宽度和高度上载.bmp图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这些行之后:

...
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
...
$this->load->library('upload', $config);
$this->upload->do_upload();

.bmp文件已成功上传到主机.但是,获取上传数据的宽度和高度会返回空值:

The .bmp file was successfully uploaded to the host. However, getting the uploaded data's width and height returns and empty value:

$imgdata = $this->upload->data();
print_r($imgdata);

也就是说, $ imgdata ['image_width'] $ imgdata ['image_height'] 根本没有任何值.

That is, $imgdata['image_width'] and $imgdata['image_height'] do not have any value at all.

我尝试上传bmp以外的其他图像文件类型.其高度和宽度是有效数字.

I've tried uploading other image file types, other than bmp. Its height and width are valid numbers.

为什么只有.bmp图片会发生这种情况?以及我该如何解决?

Why does this happen to only .bmp image? And how do I fix this?

这是 print_r() $ imgdata 的内容;

[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] => 

为什么图像文件无法识别为图像?

Why does the image file not recognized as image?

推荐答案

将system/libraries/Upload.php is_image()函数修改为:

Modified system/libraries/Upload.php is_image() function to:

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哑剧的数组值.

I added bmp mime type so that CI can recognize .bmp as an image file. Take note that I assume image/bmp to be the mime type returned in all browsers (I only test in Firefox and Google Chrome). In case there are differences, please extend the array values similar to the jpeg and png mimes.

修改后,$ imgdata ['image_width']和$ imgdata ['image_height']返回有效值.

After the modifications, $imgdata['image_width'] and $imgdata['image_height'] returns valid values.

这篇关于使用CodeIgniter的上载库0的宽度和高度上载.bmp图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆