Home > Backend Development > PHP Tutorial > Thinkphp multi-file upload implementation method, _PHP tutorial

Thinkphp multi-file upload implementation method, _PHP tutorial

WBOY
Release: 2016-07-13 10:15:33
Original
924 people have browsed it

Thinkphp multi-file upload implementation method,

The example in this article describes the implementation method of multi-file upload in Thinkphp and is shared with everyone for your reference. The specific implementation method is as follows:

The Thinkphp manual describes clearly how to upload multiple files: If you need to use multiple files, you only need to modify the form and add

Copy code The code is as follows:

Change to
Copy code The code is as follows:


  • or

    Copy code The code is as follows:


  • For now, you have two upload form fields, one for uploading pictures and one for uploading videos. The field names are image and video.
    The html code is as follows

    Copy code The code is as follows:
    Image:

    Video:

    model code:
    Copy code The code is as follows:
    protected $info= '';

    protected $_auto = array(
    array('image','upload',3,callback),//Autocomplete method
    array('video','videoupload',3,callback), //Autocomplete method
    );//Automatically fill in uploaded images to generate thumbnails
    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 suffix is ​​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();die;
    }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, let me analyze the principle of multi-file upload. Let’s take a look at the html code first
    Copy code The code is as follows:



  • This is to define the form variable as an array. In PHP, the array special variable can store multiple content of variable length, so we can customize the multi-file upload box. So how do we operate when processing in PHP? Let’s see below example.
    Copy code The code is as follows:
    protected $_auto = array(
    array('image','upload',3,callback),//Autocomplete method
    array('video','videoupload',3,callback), //Autocomplete method
    );//Automatically fill in uploaded images to generate thumbnails

    This tells thinkphp that it is an array variable. There is no need to judge the length of the traversed array and upload the code one by one like in the original PHP, because thinkphp has already done it.

    I hope this article will be helpful to everyone’s ThinkPHP framework programming.

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/904017.htmlTechArticleThinkphp multi-file upload implementation method. This article describes the Thinkphp multi-file upload implementation method and shares it with you for your reference. . The specific implementation method is as follows: In the Thinkphp manual, for...
    Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template