Zend Framework

Zend_Form_Element_File getFileMimeType() and getFileSize method

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7.1
  • Fix Version/s: 1.8.0
  • Component/s: Zend_Form
  • Labels:
    None

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;
}

Activity

Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Thomas Weidner added a comment -

Implemented with r13935

Show
Thomas Weidner added a comment - Implemented with r13935

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: