Home > php教程 > php手册 > body text

thinkPHP3.2简单实现文件上传的方法,

WBOY
Release: 2016-06-13 08:39:34
Original
1103 people have browsed it

thinkPHP3.2简单实现文件上传的方法,

本文实例讲述了thinkPHP3.2简单实现文件上传的方法。分享给大家供大家参考,具体如下:

IndexController.class.php:

<&#63;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('上传成功!');
  }
  }
}
&#63;>

Copy after login

index.html:

在view里建个和控制器同名的文件夹 Index 再建个和方法同名的html index文件,这里省略。

补充:小编在这里推荐一款本站的php格式化美化的排版工具帮助大家在以后的PHP程序设计中进行代码排版:

php代码在线格式化美化工具:http://tools.jb51.net/code/phpformat

更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《smarty模板入门基础教程》及《PHP模板技术总结》。

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!