0

After these lines:

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

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);

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

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

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


EDIT:

Here are the contents of $imgdata upon 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] => 

Why does the image file not recognized as image?

Neigyl R. Noval
  • 6,018
  • 4
  • 27
  • 45
  • i think you must add mime-type to recognize bmp as image – safarov Mar 26 '12 at 17:20
  • Check this previous post: http://stackoverflow.com/questions/7495407/uploading-in-codeigniter-the-filetype-you-are-attempting-to-upload-is-not-allo – Ben Mar 26 '12 at 17:40

1 Answers1

2

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;
    }

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.

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

Neigyl R. Noval
  • 6,018
  • 4
  • 27
  • 45