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 websitehttp://http//www.plupload.com
Or click here for this site download.
Here we are usingpluploadQueue
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:
Copy after login
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!