The proposed use of mime_type_guessers uses a nonexistent function. If you want to use the sfValidatorFile method, write array(array('sfValidatorFile', 'guessFromFileinfo')) . The proposed solution does not use mime type detection at all and leads to problems with the classic excel format on my system.
I fixed the problem by extending the sfValidatorFile class and changing the getMimeType method.
Create a new msValidatorFile.class.php file in the lib folder:
<?php class msValidatorFile extends sfValidatorFile { protected function getMimeType($file, $fallback) { $arrayZips = array( "application/zip", "application/x-zip", "application/x-zip-compressed"); $officeTypes = array( "application/vnd.ms-word.document.macroEnabled.12", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.openxmlformats-officedocument.wordprocessingml.template", "application/vnd.ms-powerpoint.template.macroEnabled.12", "application/vnd.openxmlformats-officedocument.presentationml.template", "application/vnd.ms-powerpoint.addin.macroEnabled.12", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12", "application/vnd.openxmlformats-officedocument.presentationml.slideshow", "application/vnd.ms-powerpoint.presentation.macroEnabled.12", "application/vnd.openxmlformats-officedocument.presentationml.presentation", "application/vnd.ms-excel.addin.macroEnabled.12", "application/vnd.ms-excel.sheet.binary.macroEnabled.12", "application/vnd.ms-excel.sheet.macroEnabled.12", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.ms-excel.template.macroEnabled.12", "application/vnd.openxmlformats-officedocument.spreadsheetml.template"); foreach ($this->getOption('mime_type_guessers') as $method) { $type = call_user_func($method, $file); if (null !== $type && $type !== false) { if (in_array($type, $arrayZips) && in_array($fallback, $officeTypes)) { return $fallback; } return strtolower($type); } } return strtolower($fallback); } }
Use this new validator in your form code:
$this->validatorSchema['file'] = new msValidatorFile(array('required' => false, 'path' => sfConfig::get('sf_upload_dir') ));
source share