tags:

views:

643

answers:

3

In my Symfony application, I want to set zip file as one of the mime type during the file upload, the code to do this is below:

    $this->validatorSchema ['Documents'] = new sfValidatorFile ( 
     array ('mime_types' => array(
     'application/zip', 
     'image/jpeg',
    'image/pjpeg',
    'image/png',
    'image/x-png',
   'image/gif',
     'application/x-zip',
     'application/octet-stream',
     'application/pdf') ), 
     array ('invalid' => 'Invalid file.',
      'required' => 'Select a file to upload.', 
      'mime_types' => 'The file must be of JPEG, PNG , GIF, pdf and zip format.' ) );

However, when I did the uploads, I found that all of pdf, png, gif etc can be uploaded. The only mime type that cannot be uploaded, are files that end with .zip.

What's going wrong here?

I asked a related, but different question here.

Note: I am using Symfony 1.2.7

Edit: I did some further testing with different browsers. Firefox 3 works because of 'application/octet-stream'', whereas IE works because of 'application/x-zip-compressed', Google Chrome doesn't work at all.

A: 

Do an echo or error_log to see what $uploaded_file->getMime() [or whatever the right method call is] returns for your zip files.

If the string you get is one of the strings you pass to the array, there might be a bug with sfValidatorFile (I've never used it) and you might want to try using a yml validator.

sjobe
A: 

this is a problem with mime type detection. the sfValidatorFile can use user supplied function to determine mime type. so you can write your own function to detect zip files from uploaded file if mime type that is determined by validator doesn't do the job right.

link to documentation, look at the end of page that explains file uploads.

deresh
A: 

After more testing, I believe that this is a bug in Symfony.

Ngu Soon Hui