标签:
Upload控制器下的文件上传操作
<?php namespace Home\Controller; use Think\Controller; class UploadController extends Controller{ public function upload(){ if(empty($_FILES)) { $this->display(); } else { $config = array( ‘maxSize‘ => 3145728, ‘rootPath‘ => ‘./Public/‘, ‘savePath‘ => ‘./Uploads/‘, ‘saveName‘ => ‘time‘, //保存文件名的值可以是字符串,数组和函数名 ‘exts‘ => array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘), ‘autoSub‘ => true, ‘subName‘ => array(‘date‘,‘Ymd‘) ); $upload = new \Think\Upload($config); // 实例化上传类 //上传文件 $info = $upload->upload(); if(!$info) { $this->error($upload->getError()); // 上传错误提示错误信息 } else { $this->success(‘上传成功!‘); // 上传成功 foreach($info as $file) { echo $file[‘savepath‘].$file[‘saveName‘]; } } } } ?>
upload.html模板
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <form action="__SELF__" enctype="multipart/form-data" method="post" > <input type="text" name="name" /> <input type="file" name="photo" /> <input type="submit" value="提交" ></form> </body> </html>
标签:
原文地址:http://www.cnblogs.com/sihuiming/p/5522002.html