Sorry for my English ;) Zend_File_Transfer_Adapter_Http class could not handle properly multiple file items (it set message only for first file item) and i created some improvements. It is code: <?php require_once 'Zend/File/Transfer/Adapter/Http.php';
class Myak_File_Uploader extends Zend_File_Transfer_Adapter_Http { protected $_overwrite = false; protected $_uploadedFiles = array(); public function __construct() { parent::__construct(); $this->_ensureMultipartFormData(); } public function isValid($files) { $check = $this->_getFiles($files); $this->_messages = array(); foreach ($check as $file => $content) { if (array_key_exists('validators', $content)) { foreach ($content['validators'] as $class) { $validator = $this->_validators[$class]; if (!$validator->isValid($file, $content)) { $this->_messages[] = $validator->getMessages(); } } } } return count($this->_messages) ? false : true; } public function setOverwrite($flag) { $this->_overwrite = (bool) $flag; return $this; } public function receive($files = null) { if (!$this->isValid($files)) { return false; } $check = $this->_getFiles($files); foreach ($check as $file => $content) { $directory = ''; if (null !== ($destination = $this->getDestination($file))) { $directory = $destination . DIRECTORY_SEPARATOR; } $filename = $content['name']; if (!$this->_overwrite && file_exists($directory . $filename)) { if (false === ($pos = strrpos($filename, '.'))) { $pos = strlen($filename); $ext = ''; } else { $ext = substr($filename, $pos); } $i = 0; do { $filename = substr_replace($filename, $i++, $pos) . $ext; $destinationFile = $directory . $filename; } while (file_exists($destinationFile)); } else { $destinationFile = $directory . $filename; } if (!move_uploaded_file($content['tmp_name'], $destinationFile)) { return false; } $this->_uploadedFiles[$file] = $filename; } return true; } public function getLastUploadedFile() { if (false === end($this->_uploadedFiles)) { return false; } list($key, $val) = each($this->_uploadedFiles); return array($key => $val); } public function getUploadedFiles() { return $this->_uploadedFiles; } public function getMessages() { return $this->_messages; } public function getErrors() { $errors = array(); while ($item = current($this->_messages)) { $errors[] = key($item); next($this->_messages); } return $errors; } public function setDestination($destination, $files = null) { $destination = $this->_ensureWritable($destination); parent::setDestination($destination, $files); } protected function _ensureWritable($dir) { $dir = rtrim(str_replace('\\', '/', $dir), '/'); if (!is_writable($dir) || !is_dir($dir)) { if (!file_exists($dir)) { // To create the folder with 0777 permissions, we need to set umask to zero. $umask = umask(0) ; mkdir($dir, 0777, true); umask($umask); } if (!is_writable($dir) || !is_dir($dir)) { require_once 'Myak/File/Uploader/Exception.php'; throw new Myak_File_Uploader_Exception(sprintf('Directory "%s" is not writable.', $dir)); } } return $dir; } protected function _ensureMultipartFormData() { if (count($_FILES)) { return; } if (false === strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data')) { require_once 'Myak/File/Uploader/Exception.php'; throw new Myak_File_Uploader_Exception('Submitted form does not have enctype="multipart/form-data" attribute, no files loaded!'); } } } -- View this message in context: http://www.nabble.com/Zend_File_Transfer_Adapter_Http-proposal-tp19211484p19211484.html Sent from the Zend Framework mailing list archive at Nabble.com.