ZF-5340: Zend_Form_Element_File getFileMimeType() and getFileSize method
Description
It would be nice to have a functions like getFileMimeType() and getFileSize in Zend_Form_Element_File class.
public function getFileMimeType() {
$content = $this->getTransferAdapter()->getFileInfo($this->getName());
$mimetype = $content['type'];
if (!isset($mimetype)) {
return null;
}
return $mimetype;
}
public function getFileSize() { $content = $this->getTransferAdapter()->getFileInfo($this->getName()); $bytes = $content['type'];
if (!isset($bytes)) {
return null;
}
/* this method might return formated size in specific unit like kB,mB,gB ... */
return $bytes;
}
Comments
Posted by Thomas Weidner (thomas) on 2008-12-22T12:53:44.000+0000
MimeType and FileSize might not be given. It can not guaranteed that this values are filled by the webserver.
The transfer adapter itself does therefor not provide this methods. When available it's still possible to get this data by using the getFileInfo() method. See the keys 'size' and 'type'.
Btw: Your second method will not work.
Also to note, your examples do not work when using multifiles.
Posted by Thomas Weidner (thomas) on 2009-02-01T12:41:57.000+0000
Implemented with r13935