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