ZF-5340: Zend_Form_Element_File getFileMimeType() and getFileSize method


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;



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.

Implemented with r13935