好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > thinkPHP5框架整合plupload實現圖片批量上傳功能的方法

thinkPHP5框架整合plupload實現圖片批量上傳功能的方法

熱門標簽:400電話申請辦理 全國各省地圖標注點 福建高頻外呼防封系統哪家好 周口網絡回撥外呼系統 隨州銷售電銷機器人公司 外呼系統人工客服 百度地圖標注類型是酒店 網絡電話400申請 商丘外呼系統好處

本文實例講述了thinkPHP5框架整合plupload實現圖片批量上傳功能的方法。分享給大家供大家參考,具體如下:

在官網下載plupload http://http//www.plupload.com

或者點擊此處本站下載。

這里我們使用的是pluploadQueue

在HTML頁面引入相應的css和js,然后根據示例代碼修改為自己的代碼

link rel="stylesheet" href="/assets/plupupload/css/jquery.plupload.queue.css" rel="external nofollow" type="text/css" media="screen" />
div class="form-box-header">h3>{:lang('photo')}/h3>/div>
div class="t-d-in-editor">
  div class="t-d-in-box">
    div id="uploader">
      p>{:lang('plupupload_tip')}/p>
    /div>
    div id="uploaded">/div>
  /div>
/div>
script type="text/javascript" src="/assets/plupupload/plupload.full.min.js">/script>
script type="text/javascript" src="/assets/plupupload/jquery.plupload.queue.js">/script>
script type="text/javascript">
$(function() {
// Setup html5 version
$("#uploader").pluploadQueue({
// General settings
runtimes : 'html5,flash,silverlight,html4',
url : '{:url("photo/upphoto")}',
chunk_size: '1mb',
rename : true,
dragdrop: true,
filters : {
// Maximum file size
max_file_size : '10mb',
// Specify what files to browse for
mime_types: [
{title : "Image files", extensions : "jpg,gif,png"}
]
},
// Resize images on clientside if we can
resize : {width : 320, height : 240, quality : 90},
flash_swf_url : '/assets/plupupload/Moxie.swf',
silverlight_xap_url : '/assets/plupupload/Moxie.xap',
        init: {
            PostInit: function() {
              $('#uploaded').html("");
            },
            FileUploaded : function(uploader , files, result) {
              up_image = result.response;
              if(up_image != ""){
                $("#uploaded").append("input type='hidden' name='images[]' value='"+up_image+"'/>"); //這里獲取到上傳結果
              }
            }
        }
});
});
/script>

plupload整合:

?php
/* 
 * 文件上傳
 * 
 * Donald
 * 2017-3-21
 */
namespace app\backend\logic;
use think\Model;
class Plupupload extends Model{
  public function upload_pic($file_type="data"){
    #!! IMPORTANT: 
    #!! this file is just an example, it doesn't incorporate any security checks and 
    #!! is not recommended to be used in production environment as it is. Be sure to 
    #!! revise it and customize to your needs.
    // Make sure file is not cached (as it happens for example on iOS devices)
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    /* 
    // Support CORS
    header("Access-Control-Allow-Origin: *");
    // other CORS headers if any...
    if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
        exit; // finish preflight CORS requests here
    }
    */
    // 5 minutes execution time
    @set_time_limit(5 * 60);
    // Uncomment this one to fake upload time
    // usleep(5000);
    // Settings
    //重新設置上傳路徑
    $uploads = config('uploads_dir');
    if(!empty($file_type)){
      $uploads = $uploads .$file_type."/".date("Ymd");
    }
    $targetDir = $uploads;
    //$targetDir = 'uploads';
    $cleanupTargetDir = true; // Remove old files
    $maxFileAge = 5 * 3600; // Temp file age in seconds
    // Create target dir
    if (!file_exists($targetDir)) {
        @mkdir($targetDir);
    }
    // Get a file name
    if (isset($_REQUEST["name"])) {
        $fileName = $_REQUEST["name"];
    } elseif (!empty($_FILES)) {
        $fileName = $_FILES["file"]["name"];
    } else {
        $fileName = uniqid("file_");
    }
    //重命名文件
    $fileName_arr = explode(".", $fileName);
    $fileName = myrule().".".$fileName_arr[1]; //rule()請查看上篇我的上篇博客thinkphp同時上傳多張圖片文件重名問題
    $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
    // Chunking might be enabled
    $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
    $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
    // Remove old temp files 
    if ($cleanupTargetDir) {
        if (!is_dir($targetDir) || !$dir = opendir($targetDir)) {
            die('{"jsonrpc" : "2.0", "error" : {"code": 100, "message": "Failed to open temp directory."}, "id" : "id"}');
        }
        while (($file = readdir($dir)) !== false) {
            $tmpfilePath = $targetDir . DIRECTORY_SEPARATOR . $file;
            // If temp file is current file proceed to the next
            if ($tmpfilePath == "{$filePath}.part") {
                continue;
            }
            // Remove temp file if it is older than the max age and is not the current file
            if (preg_match('/\.part$/', $file)  (filemtime($tmpfilePath)  time() - $maxFileAge)) {
                @unlink($tmpfilePath);
            }
        }
        closedir($dir);
    } 
    // Open temp file
    if (!$out = @fopen("{$filePath}.part", $chunks ? "ab" : "wb")) {
        die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
    }
    if (!empty($_FILES)) {
        if ($_FILES["file"]["error"] || !is_uploaded_file($_FILES["file"]["tmp_name"])) {
            die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
        }
        // Read binary input stream and append it to temp file
        if (!$in = @fopen($_FILES["file"]["tmp_name"], "rb")) {
            die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
        }
    } else { 
        if (!$in = @fopen("php://input", "rb")) {
            die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
        }
    }
    while ($buff = fread($in, 4096)) {
        fwrite($out, $buff);
    }
    @fclose($out);
    @fclose($in);
    // Check if file has been uploaded
    if (!$chunks || $chunk == $chunks - 1) {
        // Strip the temp .part suffix off 
        rename("{$filePath}.part", $filePath);
    }
    // Return Success JSON-RPC response
    die($filePath); //這里直接返回結果
    // die('{"jsonrpc" : "2.0", "result" : "'.$filePath.'", "id" : "id"}');
  }
}

最后Controller或Model獲取結果并保存

$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));
        }
    }
}

更多關于thinkPHP相關內容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術總結》。

希望本文所述對大家基于ThinkPHP框架的PHP程序設計有所幫助。

您可能感興趣的文章:
  • TP5框架實現上傳多張圖片的方法分析
  • tp5框架基于ajax實現異步刪除圖片的方法示例
  • tp5實現微信小程序多圖片上傳到服務器功能
  • 基于ThinkPHP5.0實現圖片上傳插件
  • ThinkPHP5+Layui實現圖片上傳加預覽功能
  • ThinkPHP5.0 圖片上傳生成縮略圖實例代碼說明
  • thinkphp5上傳圖片及生成縮略圖公共方法(分享)
  • thinkPHP5.0框架驗證碼調用及點擊圖片刷新簡單實現方法
  • Thinkphp5+plupload實現的圖片上傳功能示例【支持實時預覽】
  • Thinkphp5框架實現圖片、音頻和視頻文件的上傳功能詳解
  • ThinkPHP5+UEditor圖片上傳到阿里云對象存儲OSS功能示例
  • TP5框架實現一次選擇多張圖片并預覽的方法示例

標簽:樂山 佛山 六安 定西 十堰 海南 迪慶 南寧

巨人網絡通訊聲明:本文標題《thinkPHP5框架整合plupload實現圖片批量上傳功能的方法》,本文關鍵詞  thinkPHP5,框架,整合,plupload,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《thinkPHP5框架整合plupload實現圖片批量上傳功能的方法》相關的同類信息!
  • 本頁收集關于thinkPHP5框架整合plupload實現圖片批量上傳功能的方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 国产精品自在欧美一区| 干柴烈火肉欲李淑芬| 中国人xxxxxxx免费看视频| 欧美激情性生活| 青青草国产免费无码欧美| 免费看国产曰批40分钟视频网站99| xxxx日本在线播放免费不卡| 在线观看日批视频| 隔着内裤撞h模拟啊顶撞| 久久99精品国产麻豆不卡| 一级a一级a爱片免费视频| 天堂网www天堂在线资源库| 国产欧美一区二区三区在线老狼 | 日本护士18japanese| 中文字幕天天躁日日躁狠狠| 毛茸茸成熟女人性视频| 多汁多肉调教的高h黄文| 成人人妻久久综合影院| 免费看片的播放器| 无码成人性爽xo视频在线观看| 午夜在线精品不卡国产| h不戴套内s小说怀孕| 精品成人无码亚洲AV无码浮生| freevideos性欧美另类| 免费吻胸抓胸摸屁股视频网站 | 99re这里只有精品99| 三根硕大一起挤入她的花苞演员表 | 女仆白丝到爽??高潮痉挛机器 | 日本在线免费观看视频| 成年女人a毛片免费视频| 操日本女人b| 啊灬啊灬啊灬快灬深用力嘿嘿| 亚洲精品国产成人久久久| 他一边曰一边吃我奶头视频| 香蕉久久精品国产| 18女性下面流水| 波多野结衣女女互慰| 亚洲一级特黄大片在线播放91| 男的和男的操| japanesemature乱熟交换| 八戒,八戒电影在线看免费动漫|