ZF-5340: Zend_Form_Element_File getFileMimeType() and getFileSize method

Issue Type: Improvement Created: 2008-12-22T12:47:51.000+0000 Last Updated: 2009-02-01T12:41:57.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: S├ębastien Cramatte (scramatte) Assignee: Thomas Weidner (thomas) Tags: - Zend_Form

Related issues: Attachments:


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;



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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.