Sudheesh.M.S
Sudheesh.M.S

Reputation: 508

Mime type validation fails for high resolution images in Symfony1.0

Symfony1 mime type validation results in wrong error message as it fails to validate the high resolution images. My validation codes in the validate.yml is as follows:

mime_types:       
      - 'image/jpg'
      - 'image/jpeg'
      - 'image/png'
      - 'image/gif'
      - 'image/bmp' 
      - 'application/pdf'       
    mime_types_error: The allowed file extensions are:jpg, png, gif, bmp and pdf

But if try to upload a high resolution image of size 2-3 MB, it throws the mime type error message like:

The allowed file extensions are:jpg, png, gif, bmp and pdf

though the file type belongs to .jpg. Can anyone tell me is this a symfony1 sfvalidator bug? And how can I overcome this?

Upvotes: 0

Views: 265

Answers (1)

cb0
cb0

Reputation: 8613

Did you tried the normal sfValidatorFile ? It's used quite often in my sf1.4 app and I never had any issues.

$this->setWidget('file', new sfWidgetFormInputFile(array()));
$this->setValidator('file', new sfValidatorFile(array(
        'required'  => true,
        'path'      => sfConfig::get("sf_upload_dir").'/images',
        'max_size' => 5120000,
        'mime_types' => array('image/jpeg','image/pjpeg','image/png','image/x-png')
    ),
    array(
        'max_size' => 'Your file is too big',
        'mime_types' => 'This type of file is not allowed',
        'required' => 'Please choose a file'
    )
));

Use this in your desired Form class and customize the 'mime_types'.

If this doens't work you could try using Imagick. I hope this helps!

Upvotes: 1

Related Questions