Code for multifile Upload using the Thinkphp framework

Source: Internet
Author: User
I have introduced a lot of topics for uploading multiple files directly in php, but I encountered multiple file uploads in thinkphp at the first time, so what are the differences and commonalities between thinkphp multi-file upload and php? Next I will introduce you... I have introduced a lot of topics for uploading multiple files directly in php, but I encountered multiple file uploads in thinkphp at the first time, so what are the differences and commonalities between thinkphp multi-file upload and php? Next I will introduce a Thinkphp framework for multifile Upload. I hope it will be helpful to you.

The description of multifile upload in the Thinkphp manual is clear: to use multiple files, you only need to modify the form

 

Change

  • Or


  • Currently, you have two Upload form fields, one for uploading images and one for uploading videos. The field names are image and video.

    The html code is as follows:

    Image:Video:

    Model Code:

     SaveRule = time; $ upload-> allowExts = array ('jpg ', 'GIF', 'PNG', 'Zip', 'flv '); $ upload-> thumb = true; // specifies the video path... Only the flv suffix is supported, $ upload-> videopath = '. /Public/upload/Video/'; $ upload-> savePath = '. /Public/upload/images/'; $ upload-> thumbPrefix = '2017 _ 250 _, 150_110 _, 1__156 _'; $ upload-> thumbMaxWidth = '2016 '; $ upload-> thumbMaxHeight = '000000'; if (! In_array ('', $ var) |! In_array ('', $ _ FILES ['video'] ['name']) {if (! $ Upload-> upload () {echo $ upload-> getErrorMsg (); die;} else {$ this-> info = $ upload-> getUploadFileInfo (); if (! In_array ('', $ var) & amp ;! In_array ('', $ _ FILES ['video'] ['name']) {return $ this-> info [1] ['savename'];} elseif (! In_array ('', $ var) {return $ this-> info [0] ['savename'];} else {return false ;}}} else {return flase ;}}// upload the video protected function videoupload () {if (! In_array ('', $ var) & amp ;! In_array ('', $ _ FILES ['video'] ['name']) {return $ this-> info [0] ['savename'];} elseif (! In_array ('', $ _ FILES ['video'] ['name']) {return $ this-> info [1] ['savename'];} else {return false ;}}?>

    At the end of this article, I will analyze the multifile Upload principle. let's take a look at the html code.

  • This is to define the form variable as an array. in php, the array special variable can store multiple indefinite content, so we can customize the multifile Upload box, the following is an example of how to operate php.

    Protected $ _ auto = array ('image', 'upload', 3, callback), // method of automatic completion array ('video', 'videoupload', 3, callback), // automatic completion method); // automatically fills in the uploaded image to generate a thumbnail

    This tells thinkphp that it is an array variable and does not need to determine the length of the traversal array and then upload the code one by one, because thinkphp is ready.

    Address:

    Reprinted at will, but please attach the article address :-)

    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.