thinkphp Multi-File Upload implementation method, _php tutorial

Source: Internet
Author: User

thinkphp Multi-File Upload implementation method,


This article describes the thinkphp multi-File Upload implementation method, share to everyone for your reference. The implementation method is as follows:

thinkphp Manual for multi-File upload description is very clear: if you need to use more than one file, only need to modify the form, the

Copy the Code code as follows:
Switch
Copy the Code code as follows:



  • Or
    Copy the Code code as follows:



  • For the moment, your own upload form field is two, one upload image, one upload video. The field name is image, video.
    The HTML code is as follows

    Copy CodeThe code is as follows: Picture:

    Video:
    Model Code:
    Copy CodeThe code is as follows: protected $info = ';

    Protected $_auto = Array (
    Array (' image ', ' upload ', 3,callback),//Auto-complete method
    Array (' video ', ' Videoupload ', 3,callback),//Auto-complete method
    )///Auto fill upload image to generate thumbnail image
    protected function upload () {
    $var = $_files[' image ' [' Name '];
    Import (' ORG.Net.UploadFile ');
    $upload = new UploadFile ();
    $upload->saverule = time;
    $upload->allowexts = array (' jpg ', ' gif ', ' png ', ' zip ', ' flv ');
    $upload->thumb = true;
    Video path ... Only FLV suffixes are supported,
    $upload->videopath = './public/upload/video/';
    $upload->savepath = './public/upload/images/';
    $upload->thumbprefix = ' 250_115_,150_110_,213_156_ ';
    $upload->thumbmaxwidth= ' 250,150,213 ';
    $upload->thumbmaxheight= ' 115,110,156 ';
    if (!in_array (", $var) | |!in_array (', $_files[' video ' [' Name '])) {
    if (! $upload->upload ()) {
    echo $upload->geterrormsg ();d ie;
    }else{
    $this->info = $upload->getuploadfileinfo ();
    if (!in_array (', $var) &&!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 Video
    protected function Videoupload () {
    if (!in_array (', $var) &&!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 the article I will analyze the principle of multi-file upload, first look at the HTML code
    Copy CodeThe code is as follows:




  • This is the form variable is defined as an array, in PHP special variable It can store a number of indefinite length of content, so we can customize the multi-file upload box, then in PHP processing when we want to operate, see the example below.
    Copy CodeThe code is as follows: protected $_auto = Array (
    Array (' image ', ' upload ', 3,callback),//Auto-complete method
    Array (' video ', ' Videoupload ', 3,callback),//Auto-complete method
    )///Auto fill upload image to generate thumbnail image
    This is to tell thinkphp is an array variable, do not need to like the original ecological PHP to judge the number of the number of team leader and then upload the code, because the thinkphp has been done.

    It is hoped that this article will be helpful to everyone's thinkphp framework design.




    http://www.bkjia.com/PHPjc/904017.html www.bkjia.com true http://www.bkjia.com/PHPjc/904017.html techarticle thinkphp Multi-File Upload implementation method, this article describes the thinkphp multi-File Upload implementation method, share to everyone for your reference. The implementation method is as follows: thinkphp Manual for ...

  • 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.