Showing posts with label doc. Show all posts
Showing posts with label doc. Show all posts

Thursday, April 7, 2011

Mime Type Problem when Uploading DOC, DOCX, ODT Files in Symfony

If you create a DOC file with OpenOffice, its mimetype will be application/octet-stream, that can be anything binary data. Of course, you can't allow this mimetype at uploading.

If you try to upload DOCX and ODT files, symfony will recognise them as a ZIP archive. To corrrect this and the OpenOffice DOC mimetype problem, add the 'mime_type_guessers' option to sfValidatorFile:
$this->setValidator('filename', new sfValidatorFile(array(
      'max_size' => ...,
      'path' => ...,
      'mime_type_guessers' => array('guessFromFileinfo'),
      'required' => ...,
      ...

Wednesday, April 6, 2011

Convert DOC to TEXT with PHP and Linux

$file     = $directory.'/'.$filename;
$fileinfo = pathinfo($filename);
$content  = "";

// doc to text
if($fileinfo['extension'] == 'doc')
{
   $content = shell_exec("antiword -m UTF-8.txt -t $file");
}