Welcome Guest, Not a member yet? Register   Sign In
Upload BMP Fails.. no image_type info
#1

[eluser]yannyannyann[/eluser]
Hello,

I am trying to upload a BMP file :

this is the result of the CI upload data function :
Code:
$this->upload->data();

    [file_name] => blackbuck4.bmp
    [file_type] => application/octet-stream
    [file_path] => /mypath/
    [full_path] => /mypath/blackbuck4.bmp
    [raw_name] => blackbuck4
    [orig_name] => blackbuck.bmp
    [file_ext] => .bmp
    [file_size] => 768.05
    [is_image] =>
    [image_width] =>
    [image_height] =>
    [image_type] =>
    [image_size_str] =>


As you can see there is no information for the last 5 variables.

Therefore I have added the type in my MIMES.php file :

Code:
'bmp'    =>    array('image/bmp','application/octet-stream','image/x-ms-bmp'),

But I still get the same result : No information for is_image, image_width, image_height, image_type, image_size_str.


Any idea ?
#2

[eluser]Evil Wizard[/eluser]
The version of the upload class I have checks that the uploaded file is an image by comparing the file extension to an array of image mime types. The array in the code seems to be hard coded and ignores the mimes.php file
Code:
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');
    
    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';
    }

    $img_mimes = array(
                        'image/gif',
                        'image/jpeg',
                        'image/png',
                        );

    return (in_array($this->file_type, $img_mimes, TRUE)) ? TRUE : FALSE;
}
The set_image_properties() method checks the is_image() method to determine if the image properties need to be set, and uses getimagesize() to assign the values.

You need to change the last part of the function to include your bmp mime type as a valid image mime.
Code:
$img_mimes = array(
                        'image/gif',
                        'image/jpeg',
                        'image/png',
                                                'image/x-ms-bmp'
                        );
#3

[eluser]yannyannyann[/eluser]
Thank you,

but do I really need to change the way the Class is written ?

I mean I have been using CI mimes.php file as is since a while with a lot of file types (audios, video, images)
I have always solved my problems of Mime Types by adding info in mimes.php

Why is it just not working with BMP files ?
#4

[eluser]Evil Wizard[/eluser]
I guess bitmaps were overlooked when the upload class was being coded, and there doesn't seem to be an easy way to extract only image mimes from the mimes.php file to test against.
#5

[eluser]yannyannyann[/eluser]
Hi CodeIgniter Community,

Has anyone have had the same problem before ?

Is it really something linked to the core of code igniter ?




Theme © iAndrew 2016 - Forum software by © MyBB