本⽂实例讲述了thinkPHP3.2简单实现⽂件上传的⽅法。分享给⼤家供⼤家参考,具体如下:IndexController.class.php:
namespace 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⽂件,这⾥省略。
补充:⼩编在这⾥推荐⼀款本站的php格式化美化的排版⼯具帮助⼤家在以后的PHP程序设计中进⾏代码排版:更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》及《》。希望本⽂所述对⼤家基于ThinkPHP框架的PHP程序设计有所帮助。
因篇幅问题不能全部显示,请点此查看更多更全内容