file has a false mimetype of 'application/octet-stream'

For programming and general questions on Zend Framework

file has a false mimetype of 'application/octet-stream'

Postby dzun2358 on Sun Feb 17, 2013 3:01 pm

My operating system is 64-bit Windows 7 Home Premium.
I am trying to build a website based on:
1) PHP 5.4.7 (This version enables fileinfo by default)
2) Zend Framework 1.12.0

I am building a form that uploads product images which are inserted into database as the following:

Code: Select all
<form method="post"  action="" id="frmAddNewShoes" name="frmAddNewShoes" onsubmit="return frmAddNewShoes_onsubmit(this);" enctype="multipart/form-data">
<table cellpadding="0" cellspacing="5" width="100%" align="center">
   <tr>
      <td width="120" align="right" nowrap="nowrap" valign="top"><strong>Shoes Image:</strong></td>
                <td><input type="file" id="imgfile" name="imgfile"></td>
   </tr>
        <tr>
               <td></td>
               <td align="left"><input type="image" src="<?php echo $this->baseUrl().'/images/img-addnew.jpg'?>" style="width:100px; height:50px;"></td>
       </tr>

<script language="javascript" type="text/javascript">
//<![CDATA[
function frmAddNewShoes_onsubmit(frm)
{
   return true;   
}
//]]>
</script>


When submitting the form, function indexAction() is called as the following:

Code: Select all
    public function indexAction()
    {
       if ($this->_request->isPost())
      {
         $adapter = new Zend_File_Transfer_Adapter_Http();         
         $adapter->addValidator('Count', false, array('min' =>1, 'max' => 1))
                             ->addValidator('IsImage', false, array('jpeg, png, gif'))
                  ->addValidator('MimeType', false, array('image/jpeg',  'image/png', 'image/gif'))
                       ->addValidator('Extension',false,'jpg,png,gif')
                                      ->addValidator('Size', false, array('max' => '512kB'));
         $adapter->setDestination(APPLICATION_PATH . '/../images/shoes/');

         if (!$adapter->isValid())
         {
             throw new Exception('Bad image data: '.implode(',', $adapter->getMessages()));   
         }
         
         try
         {
                      $adapter->receive();                                                         
         }
         catch (Zend_File_Transfer_Exception $e)
         {
              throw new Exception('Bad image data: '.$e->getMessage());
         }         
      }
      
      $layout = $this->_helper->layout();
      $layout->setLayout('admin-layout');
    }


I press the Browse button and select an image, for example activation.jpg. Then I submit form, I get the following error message:
Message: Bad image data: The mimetype of file 'activation.jpg' could not be detected,The mimetype of file 'activation.jpg' could not be detected

I search over the Internet for the solution and do the following:
1) Pasting magic files including magic, magic.mgc, magic.mime to folder C:\mime
2) Modifying $_magicfile property in Zend_Validate_File_MimeType so that it points to the location of magic files

Code: Select all
    protected $_magicfile = 'C:\mime';


Submiting the form, this time I get the following error message:
Message: Bad image data: File 'activation.jpg' is no image, 'application/octet-stream' detected,File 'activation.jpg' has a false mimetype of 'application/octet-stream'

To this point, I do not know how to do.
I do not know whether my magic files is valid or not.
Please help me solve this error
dzun2358
 
Posts: 1
Joined: Sun Feb 17, 2013 11:40 am

Return to Zend Framework

Who is online

Users browsing this forum: Google [Bot] and 13 guests