Home > Backend Development > PHP Tutorial > ThinkPHP3.2 simple method to implement file upload, _PHP tutorial

ThinkPHP3.2 simple method to implement file upload, _PHP tutorial

WBOY
Release: 2016-07-12 08:52:05
Original
839 people have browsed it

thinkPHP3.2 simply implements file uploading method,

This article describes the example of thinkPHP3.2 simply implements file uploading method. Share it with everyone for your reference, the details are as follows:

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:

Create a folder Index in the view with the same name as the controller, and then create an html index file with the same name as the method, which is omitted here.

Supplement: The editor here recommends a PHP formatting and beautifying typesetting tool on this website to help you code typesetting in future PHP programming:

PHP code online formatting and beautification tool: http://tools.jb51.net/code/phpformat

Readers who are interested in more thinkPHP-related content can check out the special topics on this site: "ThinkPHP Getting Started Tutorial", "ThinkPHP Common Methods Summary", "Smarty Template Basic Tutorial" and "PHP Template Technology Summary".

I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127887.htmlTechArticlethinkPHP3.2 simply implements file uploading. This article illustrates how thinkPHP3.2 simply implements file uploading. Share it with everyone for your reference, the details are as follows: IndexController...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template