/ Published in: PHP
A sample wrapper class around Zend_File_Transfer_Adapter_Http
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php class App_Model_Upload { private $upload; public function __construct($path = '/home/account/public_html/uploads') { $this->upload = new Zend_File_Transfer_Adapter_Http(); $this->upload->addValidator('Extension', false, 'jpg,jpeg,png,gif') ->addValidator('Size', false, 2097152) //max of 2mb = 2097152 /* ->addValidator('ImageSize', false, array('minwidth' => 100, 'maxwidth' => 100, 'minheight' => 1000, 'maxheight' => 1000))*/ $renameFilter = new Zend_Filter_File_Rename( $path ); $files = $this->upload->getFileInfo(); foreach($files as $fileID => $fileInfo) { if(!$fileInfo['name']=='') { 'source' => $fileInfo['tmp_name'], 'overwrite' => true ) ); } } // add filters to Zend_File_Transfer_Adapter_Http $this->upload->addFilter($renameFilter); return $this; } public function isValid() { return $this->upload->isValid(); } public function getMessages() { return $this->upload->getMessages(); } public function upload() { try { $this->upload->receive(); } catch (Zend_File_Transfer_Exception $e) { //This is a tad dirty throw new Exception('Bad file data: '.$e->getMessage()); } return $this; } public function getUpload() { return $this->upload; } }