Home  >  Article  >  Backend Development  >  thinkPHP5 framework integrates plupload to realize batch upload of images

thinkPHP5 framework integrates plupload to realize batch upload of images

不言
不言Original
2018-05-04 14:01:192525browse

This article mainly introduces the integration of thinkPHP5 framework with plupload to realize batch upload of images. It has certain reference value. Now I share it with you. Friends in need can refer to it.

This article describes the integration of thinkPHP5 framework with examples. plupload is a method to implement the batch upload function of images. Share it with everyone for your reference, the details are as follows:

Download plupload on the official website http://http//www.plupload.com

Or click here for this site download.

Here we are using pluploadQueue

Introduce the corresponding css and js into the HTML page, and then modify it to your own code based on the sample code


{:lang('photo')}

{:lang('plupupload_tip')}

plupload integration:

Finally the Controller or Model gets the result and saves it

$images = $request->post('images/a'); //这里一定要注意, thinkphp通过name获取post数组时会获取不到数据,需要在name后加/a,表示获取数组详见Request的typeCast
model('PhotoImage')->query_insert($images, $id);//批量插入图片

/**
* 强制类型转换
* @param string $data
* @param string $type
* @return mixed
*/
private function typeCast(&$data, $type)
{
    switch (strtolower($type)) {
      // 数组
      case 'a':
        $data = (array) $data;
        break;
      // 数字
      case 'd':
        $data = (int) $data;
        break;
      // 浮点
      case 'f':
        $data = (float) $data;
        break;
      // 布尔
      case 'b':
        $data = (boolean) $data;
        break;
      // 字符串
      case 's':
      default:
        if (is_scalar($data)) {
          $data = (string) $data;
        } else {
          throw new \InvalidArgumentException('variable type error:' . gettype($data));
        }
    }
}

Related recommendations:

Image upload plug-in based on ThinkPHP5.0

How to use Memcached to cache data in the ThinkPHP framework

The above is the detailed content of thinkPHP5 framework integrates plupload to realize batch upload of images. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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