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