本文實例講述了thinkPHP3.2簡單實現文件上傳的方法。分享給大家供大家參考,具體如下:
IndexController.class.php:
<?phpnamespace Home/Controller;use Think/Controller;class IndexController extends Controller { function index(){ $this->display(); } public function upload(){ $upload = new /Think/Upload();// 實例化上傳類 $upload->maxSize = 3145728 ;// 設置附件上傳大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 設置附件上傳類型 $upload->rootPath = './Uploads/'; // 設置附件上傳根目錄 $upload->savePath = ''; // 設置附件上傳(子)目錄 // 上傳文件 $info = $upload->upload(); print_r($info);exit; if(!$info) {// 上傳錯誤提示錯誤信息 $this->error($upload->getError()); }else{// 上傳成功 $this->success('上傳成功!'); } }}?>
index.html:
在view里建個和控制器同名的文件夾 Index 再建個和方法同名的html index文件,這里省略。