Greetings all,
Thanks for reading this.

We've recently had an error on one of our webpages where users can upload image files. This upload form has been working fine for some time now and I'm thining this might be related to the mime-type of the image uploaded. I've not seen a image/x-citrix-pjpeg file before.

My question is does the php image function imagecreatefromjpeg() work with the mime-type image/x-citrix-pjpeg?

synopsis of the code:
We do a preg_match to see if the image is in the types we allow ( gif, jpg, jpeg and png ). It passes this since due to the jpeg in pjpeg.
Next we get the image size using getimagesize() to see if it needs to be resized.
If it does I call resizeImage(), a homegrown function in an includes file.
If the image cannot be resized, we return false and do a confess with "the image is too large and cannot be resized" message. This is what we saw in this paticular error.

In resizeImage() we have a switch statement:

$info = getimagesize($file);  // $file passed into function

switch ($info[2]) {
    case IMAGETYPE_GIF:
        $image = imagecreatefromgif($file);
    break;
    case IMAGETYPE_JPEG:
        $image = imagecreatefromjpeg($file);
    break;
    case IMAGETYPE_PNG:
        $image = imagecreatefrompng($file);
    break;
    default:
        return false;
}

I'm thinking that the case line IMAGETYPE_JPEG is not getting run and the code is dropping through to the return false. This is why I believe the mime-type image/x-citrix-pjpeg is causing this.

Thoughts?

Here is the info in the $_FILES array.

$_FILES  
array(1) { ["imagefile"]=> array(5) { ["name"]=> string(52) "35806_1418596538051_1026759583_31036444_387798_n.jpg" ["type"]=> string(20) "image/x-citrix-pjpeg" ["tmp_name"]=> string(14) "/tmp/phpGxBAgc" ["error"]=> int(0) ["size"]=> int(123661) } }

Thanks for any ideas or tips.

    If [man]getimagesize[/man] does not recognise the format, it returns FALSE, and triggers a Warning (is this the error you mention in passing? What sort of error was it?).

    It looks at the actual bits of the file, and not at the MIME type provided by the client, not just because the latter cannot be trusted to be correct or accurate, but also because it won't be available in many cases.

    What value does [font=monospace]$info[2][/font] have for one of these images? [font=monospace]IMAGETYPE_JPEG == 2[/font]. For that matter, what is reported by [font=monospace]$info['mime'][/font] (which is getimagesize()'s own choice). If getimagesize() is not choking on a file it doesn't recognise, then it is recognising it as something.

      The error we get here is a confess that we force if the resizeImage() function returns false. I posted this in my inital post:

      If the image cannot be resized, we return false and do a confess with "the image is too large and cannot be resized" message. This is what we saw in this paticular error.

      From PHP manual for getImageSize(): Index 2 is one of the IMAGETYPE_XXX constants indicating the type of the image. I do not know what IMAGETYPE_XXX would be for this type of image. My guess would be IMAGETYPE_JPEG, but since the function is returning false, I do not know.

      I'm not experienced enough in php to did into the inner workings of the libs to see if getImageSize recognizes images of type image/x-citrix-pjpeg (bits not type).

      I'm going to try and create (or get) an image with mime-type: image/x-citrix-pjpeg and test with it.

        Write a Reply...