dqcz57269 2016-07-07 13:21
浏览 65

blueimp JQuery插件自定义用户dirs用法

I have UploadHandler class with parameters and constructor:

    function __construct($profile_id, $options = null, $initialize = true, $error_messages = null) {
    $this->response = array();
    $this->options = array(
        'script_url' => $this->get_full_url().'/'.basename($this->get_server_var('SCRIPT_NAME')),
        'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/files/'.$profile_id.'/', //'.$this->options['profile_id'].'/',
        'upload_url' => $this->get_full_url().'/files/'.$profile_id.'/', //.$profile_id.'/' ---'.$this->options['profile_id'].'/',
        'input_stream' => 'php://input',

My $profile_id is ID of users profile. This value placed as hidden value in file upload form. Then file upload is done I have my file in directory - specified to user by profile_id.

But if I need to see existing files for user Plugin doing scan of root 'server/php/' directory.

Ok. In time of writing this post my case is going work good. Please read following to add users dir on download moments.

  1. In this case you need switch POST/GET variable in server/php/index.php:

    if(isset($_POST['profile_id'])) {
    $profile_id = $_POST['profile_id'];}
    

    if(isset($_GET['profile_id'])) { $profile_id = $_GET['profile_id']; }

  2. Put $profile_id in class(index.php):

    $upload_handler = new CustomUploadHandler($profile_id, $options);

  3. Modify main.js of blueimp from line 58(replace by following code):

    } else {
    // Load existing files:
    $('#fileupload').addClass('fileupload-processing');
    //var profile_id = Session["profile_id"];
    //var profile_id = oForm.elements["profile_id"].value;
    //var ee = $('#fileupload').fileupload('option', 'url');
    var form = $("#fileupload");
    var profile_id = $("[name='profile_id']", form).val();
    //alert(ee);
    //alert(profile_id);
    $.ajax({
        // Uncomment the following to send cross-domain cookies:
        //xhrFields: {withCredentials: true},
        url: $('#fileupload').fileupload('option', 'url') +'?profile_id='+profile_id,
        //url: 'server/php/files/'+profile_id +'/',
        dataType: 'json',
        context: $('#fileupload')[0]
    }).always(function () {
        $(this).removeClass('fileupload-processing');
    }).done(function (result) {
        $(this).fileupload('option', 'done')
            .call(this, $.Event('done'), {result: result});
    });
    

    }

  4. You need to have hidden input with your user (ID,XX,TTT) in #fileupload:

  5. Enjoy!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用