- //实例化文件上专类
- $fName=$this->_request->getPost('fName');
- $adapter = new Zend_File_Transfer_Adapter_Http();
- //存放上传文件的文件夹
- $adapter->setDestination('/opt/lampp/htdocs/blog/upload');
- //上传配置
- $adapter
- ->addValidator ( 'Extension', false, $configs['extension'])//文件格式限制
- ->addValidator('Size', false, array('min' =>floatval($configs['minsize']),
- 'max' => floatval($configs['maxsize'])))//设置上传文件的大小在1-2M之间
- ->addValidator ( 'Count', false, array('min' => intval($configs['mincount']),
- 'max' => intval($configs['maxcount'])) );//上传文件数量
- //重命名配置
- $fileInfo = $adapter->getFileInfo();//获取基本配置
- $extName=$this->getExtension($fileInfo);//获取扩展名
- $filename=md5(time()+$fileInfo['fFile']['name']).'.'.$extName;//重命名
- $adapter->addFilter('Rename', array('target' => $filename, 'overwrite' => true));//执行重命名
-
- //返回上传后出现在信息
- if (!$adapter->receive())
- {
- $messages = $adapter->getMessages ();//检测
- //Zend_Debug::dump($messages);
- $message='';
- if(is_array($messages))
- {
- foreach($messages as $k=>$v)
- {
- $message.=$k.':'.$v.'
';
- }
- }
- else
- {
- $message=$messages;
- }
- }
- else
- {
- $this->view->message='上传成功!';
- }
复制代码
- /**
- * 获取文件扩展名
- * @param String $name 文件名词
- * @author
- */
- public function getExtension ($name)
- {
- $fname='';
- if($name)
- {
- foreach ($name as $val)
- {
- $fname=$val['name'];
- }
- $exts = @split("[/\\.]", $fname) ;
- $n = count($exts)-1;
- $exts = $exts[$n];
- return $exts;
- }
- }
复制代码
|
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31