Validating web images in Symfony 1.2.8 with PHP 5.3.0

No Gravatar

If you’re developing a Symfony 1.2.8 (and possibly other older releases) application with PHP 5.3.0 you won’t be able to use the sfValidatorFile with mime_categories set to web_images without changing Symfony code. Was that really English? Since PHP 5.3.0 finfo will return charset information with the mime type. See more about this change in this php bug report.

If you try to use web_images, the validator will fail on images it should accept with an error like: “Invalid mime type (image/gif; charset=binary).”

As a work around until this is fixed, you can change your file validator to something like this:

$this->validatorSchema['image_custom'] = new sfValidatorFile(array(
  'mime_types' => array(
    'image/gif; ch arset=binary',
    'image/jpeg; charset=binary',
    'image/pjpeg; charset=binary',
    'image/png; charset=binary',
    'image/x-png; charset=binary',
    'image/gif; charset=binary',
  )
));

Hope this helps!


				
				

3 Responses to “Validating web images in Symfony 1.2.8 with PHP 5.3.0”

  1. Nikola PetkanskiNo Gravatar says:

    Thanks for the guidance. I’ve actually inherited the sfValidatorFile object like this:

    addOption(‘mime_categories’, array(
    ‘web_images’ => array(
    /* PHP 5.2.x mime_magic mime types */
    ‘image/jpeg’,
    ‘image/pjpeg’,
    ‘image/png’,
    ‘image/x-png’,
    ‘image/gif’,
    /* PHP 5.3.x finfo mime types (rfc 2045) */
    ‘image/gif; charset=binary’,
    ‘image/jpeg; charset=binary’,
    ‘image/pjpeg; charset=binary’,
    ‘image/png; charset=binary’,
    ‘image/x-png; charset=binary’,
    ‘image/gif; charset=binary’
    )));
    }
    }

    It appears to be working just fine now. :)

  2. Nikola PetkanskiNo Gravatar says:

    Oops, my comment did not seem to be properly escaped by your blog.. Sorry :]

  3. XavierNo Gravatar says:

    Thanks for your post, it helps me fixing my bug.

Leave a Reply