I’m having trouble determining the file-type of an image I uploaded with Zend Framework.
Everytime I try to determine the filetype with $_FILES[‘File’][‘type’], I always get applicationoctet-stream. Only when I determine the type before checking if the form is posted do I get the right extension. Does anyone know why? Is there a nicer way of dealing with this?
this works:
$form = new Form_Reg;
$this->view->Reg = $form;
if(isset($_FILES['File']['type'])){
$filetype = $file = $_FILES['File']['type'];
}
if ($this->getRequest()->isPost()){
$formData = $this->_request->getPost();
if($form->isValid($formData)){
echo $filetype;
exit;
}
}
This doesn’t work:
$form = new Form_Reg;
$this->view->Reg = $form;
if ($this->getRequest()->isPost()){
$formData = $this->_request->getPost();
if($form->isValid($formData)){
$filetype = $file = $_FILES['File']['type'];
echo $filetype;
exit;
}
}
I’ve seen more questions about this on stackoverflow but couldn’t find the answer that solved my particular problem. The problem was that zend form couldn’t validate if the uploaded file was an image, as soon as it started processing the form the filetype would change into applicationoctet-stream, no mather what kind of file was uploaded.
The trick was to adjust the php.ini, look for this and uncomment it: extension=php_fileinfo.dll.
Still I wonder what zend_form does that fileinfo is needed, the $_FILES global works without fileinfo.