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.
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']; }
Put $profile_id in class(index.php):
$upload_handler = new CustomUploadHandler($profile_id, $options);
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});
});
}
You need to have hidden input with your user (ID,XX,TTT) in #fileupload:
Enjoy!