Hi, Am Freitag, den 26.01.2007, 15:02 +0100 schrieb Georg von der Howen: > Hi, > > I can't find specific methods to access data about uploaded files from > a Zend_Controller_Request_Http object. Is there a reason for not > supporting the global $_FILES in that class?
I would suggest to implement Zend_Controller_Request_Http_Files to wrap $_FILES in a sensible way. Extending Zend_Controller_Request_Http: class Zend_Controller_Request_Http implements Zend_Controller_Request_Interface { ... public function __get($variable) { switch ($variable) { case 'files': if ($this->_files === null) $this->_files = new Zend_Controller_Request_Http_Files; return $this->_files; } } } class Zend_Controller_Request_Http_Files { public function hasFiles() { return !empty($_FILES); } // Mask can be an array of requirements that must be fullfilled if we move it // array('mimetype' => 'application/.*', 'size' => '<1MB') public function moveFiles($target, array $mask = null) { foreach ($_FILES as $file) { ... } } public function hasFile($name) {} public function moveFile($file, $target, array $mask = null) { } } So, in your controller you do the following thing: public function myAction() { if ($this->getRequest()->files->hasFile('myfile')) { try { $this->getRequest()->files->moveFile('myfile', MY_UPDLOAD_DIR); } catch (Zend_Controller_Request_Http_Files_Exception $e) { $this->getView()->upload_error = gettext($e->getMessage()); } } } Greetings, Lars Strojny
signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil