ThinkPHP learning notes (14) upload files

Source: Internet
Author: User
ThinkPHP learning notes (14) The Action settings are required for uploading files, including the file introduction of UploadFile & lt ;? Php/*** file Upload processing function ** @ authoradmin **: when uploading multiple files, you can add [] ThinkPHP learning notes (14th) to the name in the input file to upload files.

Action settings are required, including file introduction of UploadFile.

 Select (); $ this-> assign ('alist', $ list); $ this-> display ();} function upload () {// custom model if (empty ($ _ FILES) {$ this-> error ("file upload required ");} else {$ msg = $ this-> up (); if (isset ($ msg) {$ result = $ this-> insertDb ($ msg); if ($ result) {$ this-> success ('uploaded successfully');} else {$ this-> error ('failed to save that ');}} else {$ this-> error ($ msg) ;}} private function insertDb ($ data) {$ file = M ('file'); $ result = true; for ($ I = 0; $ I <count ($ data); $ I ++) {$ data ['Filename'] = $ data [$ I] ['savename']; if (! $ File-> data ($ data)-> add () {return false ;}} return true;} private function up () {import ('org. net. uploadFile '); $ upload = new UploadFile (); $ upload-> maxSize = '000000'; // The size is-1; the unit is bytes $ upload-> savePath = '. /Public/'; // upload path: We recommend that you use a subdirectory of the main intersection or level directory to $ upload-> saveRule = 'uniqid'; // Save the rule: the default value is uniqid $ upload-> hashType = 'md5'; // hash verification method. the default value is MD5 $ upload-> autoCheck = false; $ upload-> uploadReplace = true; $ upload-> allowExts = array ('jpg ', 'p Ng '); // The format of the file to be uploaded $ upload-> allowTypes = array ('image/png', 'image/jpg '); // mime type of the file $ upload-> thumb = true; // whether to enable the image file thumbnail $ upload-> thumbMaxWidth = '000000'; // you can use, split, write multiple maximum widths $ upload-> thumbMaxHeight = '000000'; // corresponds to the width one by one $ upload-> thumbPrefix ='s _, m _'; // prefix of the thumbnail file, one-to-one correspondence with width // $ upload-> thumbPath = ''; // save path of the thumbnail, if it is null, directly upload the file to $ upload-> savePath // $ upload-> thumbFile = ''; // The name of the thumbnail file is generally not used, you can directly use the prefix $ upload-> thumbRemoveOrigin = 1; // generate a new graph. Whether to delete the source image // $ upload-> autoSub = false; // whether to use sub-directories for saving // $ upload-> subType = ''; // How to create sub-directories, by default, it is created for hash. you can also set it to date // $ upload-> dateFormat = ''; // specify the format of date in the subdirectory // $ upload-> hashLevel = ''; // hash level if ($ upload-> upload () {$ msg = $ upload-> getUploadFileInfo (); dump ($ msg); return $ msg ;} else {$ this-> error ($ upload-> getErrorMsg (); return $ upload-> getErrorMsg () ;}}?>

Html

 <!--{$title}-->
 
  "/>"/>
 


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.