Welcome to the Csdn-markdown Editor

Source: Internet
Author: User

Thinkphp3.2 Upload Detailed

Recently in learning to use the thinkphp3.2 framework to write a small project, to find work when used. According to the official document file upload function, the result is wrong, in the QQ group asked for half a day did not find the answer, finally follow the online video to do finally realize the upload function, write blog to celebrate.

DataController.class.php

namespace Admin\Controller; Use Think\Controller; class datacontroller extends Controller {     Public  function index(){        $this->display (); } Public  function upload(){               $upload=New\think\upload ();//instantiation of upload class        $upload->maxsize =3145728;//Set attachment upload size        $upload->exts =Array(' jpg ',' gif ',' PNG ',' JPEG ');//Set attachment upload type        $upload->savepath ='./';//Set attachments upload (sub) directory        //Upload files        $info=$upload->upload ();if(!$info) {//Upload error message            $this->error ($upload->geterror ()); }Else{//Upload successful            $this->success (' upload success! '); }    }}

In the admin module, create a new data folder under the View folder and create a new index.html under the Data folder (this index.html is the template for the index method under the data module).

Index.html

<! DOCTYPE html><html><head><meta charset="UTF-8"><title>File Upload</title></head><body>Single File Upload<form Action="./upload" enctype="Multipart/form-data"  Method="POST" ><input type="file" name="Photo" /><input type="Submit" value="Submit" ></form></body></html>

Said simple, but I think for a long time to solve, no master can only explore their own.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Welcome to the Csdn-markdown Editor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.