<?php namespace Home\Controller; use Think\Controller; class DocumentController extends Controller { function xianshi(){ if(empty($_FILES)) { $this->display(); } else { $upload=new \Think\Upload(); //设置上传文件参数 $upload->maxSize=1024000;//文件大小 $upload->exts=array('jpg',"png","gif","jpeg");//文件类型 $upload->rootPath="./Public"; $upload->savePath="uploads/";//上传路径,必须是这样写,基于根路径 $upload->saveName='time'; //上传方法 $info=$upload->upload(); var_dump($info); } } }
前台:
<body> <form action="__ACTION__" method="post" enctype="multipart/form-data"> <input type="file" name="file" /> <input type="submit" value="上传"/> </form> </body>
No Excuse~