PHP Zend文件上传类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP Zend文件上传类相关的知识,希望对你有一定的参考价值。
<?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('Count', false, array('min' => 1, 'max' => 2));
/* ->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']=='') {
$renameFilter->addFile(array(
'source' => $fileInfo['tmp_name'],
'target' => $path.'/'.time().'_'.$fileInfo['name'], //Set timeindex on file name for uniqueness
'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;
}
}
以上是关于PHP Zend文件上传类的主要内容,如果未能解决你的问题,请参考以下文章
PHP上传文件到指定目录(Zend Studio 12.5)
在单机模式下使用 Zend_PDF,如何设置土地类的包含
文件上传表单的 Zend 验证器大小 - Zend Framework 2.3
文件上传表单的 Zend 验证器大小 - Zend Framework 2.3
php中啥是第三方类库
Zend 框架与 PHP,更改类标签