thinkphp frame: File Upload

Source: Internet
Author: User

Implementing the File Upload function requires a controller, and then the displayed page

1. Create a new controller under controllers TestController.class.php

2. Create an action method

<?phpnamespace home\controller;use Think\controller;class TestController extends Controller {public function Shangchuan () {$this->show ();//Display template page}}

3. Create a new test folder under the View folder in the home folder, creating the uploaded template page under the test folder

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

4. Let the upload point to an operation method, create a new WJSC operation method

<?phpnamespace home\controller;use Think\controller;class TestController extends Controller {public function Shangchuan () {$this->show ();} Public Function WJSC () {$u = new \think\upload ();//instantiation of the upload class  \ is the initial namespace Think is the root namespace Upload is the class $u->maxsize = 1024000;// Set File Size $u->rootpath = "./public/";//the root path of file storage $u->savepath = "./upload/";//sets the location of the currently uploaded file to be stored $u->exts = array (' jpg ' gif ', ' PNG ', ' jpeg ');//Set the attachment upload type $info = $u->upload ();//upload the file and return the file information if ($info) {echo "Upload is successful, the file is stored in:". $info ["Files"] [' Savepath '];} Else{echo $u->geterror ();}}

Take a look at the effect of the implementation:

The save path for file uploads is displayed (relative to the root path)

The following is a reference to the upload parameters and file upload information parameters

thinkphp frame: File Upload

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.