Various QQ File uploaders updates
This commit is contained in:
@@ -8,18 +8,20 @@ $PRINT_ALL = 1;
|
|||||||
require 'config.inc';
|
require 'config.inc';
|
||||||
// class load
|
// class load
|
||||||
$base = new CoreLibs\Basic();
|
$base = new CoreLibs\Basic();
|
||||||
|
$base->debug('AJAX UPLOAD', 'START Backend');
|
||||||
// set max upload size
|
// set max upload size
|
||||||
$MAX_UPLOAD_SIZE = $base->StringByteFormat(ini_get('upload_max_filesize'));
|
$MAX_UPLOAD_SIZE = $base->StringByteFormat(ini_get('upload_max_filesize'));
|
||||||
|
|
||||||
// test for qqFileUploader (AJAX side)
|
// test for qqFileUploader (AJAX side)
|
||||||
$allowedExtensions = array ('csv', 'zip', 'jpg', 'pdf');
|
$allowedExtensions = array ('csv', 'zip', 'jpg', 'pdf', 'bz2');
|
||||||
$sizeLimit = $MAX_UPLOAD_SIZE; // as set in php ini
|
$sizeLimit = $MAX_UPLOAD_SIZE; // as set in php ini
|
||||||
$base->debug('AJAX UPLOAD', 'Size: '.$sizeLimit.', Memory Limit: '.ini_get('memory_limit'));
|
$base->debug('AJAX UPLOAD', 'Size: '.$sizeLimit.', Memory Limit: '.ini_get('memory_limit'));
|
||||||
$uploader = new CoreLibs\Upload\qqFileUploader($allowedExtensions, $sizeLimit);
|
$uploader = new CoreLibs\Upload\qqFileUploader($allowedExtensions, $sizeLimit);
|
||||||
// either in post or get
|
// either in post or get
|
||||||
$_action= $_POST['action'] ? $_POST['action'] : $_GET['action'];
|
$_action= $_POST['action'] ? $_POST['action'] : $_GET['action'];
|
||||||
$_task_uid = $_POST['task_uid'] ? $_POST['task_uid'] : $_GET['task_uid'];
|
$_task_uid = $_POST['task_uid'] ? $_POST['task_uid'] : $_GET['task_uid'];
|
||||||
$base->debug('AJAX UPLOAD', 'Action: '.$_action.', Task UID: '.$_task_uid);
|
$get_post['start'] = microtime(true);
|
||||||
|
$base->debug('AJAX UPLOAD', 'Action: '.$_action.', Task UID: '.$_task_uid.' => '.$base->dateStringFormat($get_post['start']));
|
||||||
|
|
||||||
$upload_path = ROOT.MEDIA.UPLOADS;
|
$upload_path = ROOT.MEDIA.UPLOADS;
|
||||||
$get_post['result'] = $uploader->handleUpload($upload_path, false);
|
$get_post['result'] = $uploader->handleUpload($upload_path, false);
|
||||||
@@ -30,10 +32,13 @@ $get_post['filename'] = $uploader->uploadFileName;
|
|||||||
$get_post['type'] = $uploader->uploadFileExt;
|
$get_post['type'] = $uploader->uploadFileExt;
|
||||||
$get_post['filesize'] = filesize($uploader->uploadFileName);
|
$get_post['filesize'] = filesize($uploader->uploadFileName);
|
||||||
$get_post['filesize_formated'] = $base->ByteStringFormat($get_post['filesize']);
|
$get_post['filesize_formated'] = $base->ByteStringFormat($get_post['filesize']);
|
||||||
|
$get_post['end'] = microtime(true);
|
||||||
|
$get_post['time'] = $get_post['end'] - $get_post['start'];
|
||||||
|
|
||||||
|
$base->debug('AJAX RESULT', $base->printAr($get_post));
|
||||||
// return data
|
// return data
|
||||||
$output = htmlspecialchars(json_encode($get_post), ENT_NOQUOTES);
|
$output = htmlspecialchars(json_encode($get_post), ENT_NOQUOTES);
|
||||||
$base->debug('AJAX USAGE', $output);
|
// $base->debug('AJAX JSON', $output);
|
||||||
print $output;
|
print $output;
|
||||||
|
|
||||||
$base->printErrorMsg();
|
$base->printErrorMsg();
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ $base->debug('UPLOADED FRONT', 'With max size: '.$MAX_UPLOAD_SIZE);
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>File upload AJAX</title>
|
<title>File upload AJAX</title>
|
||||||
|
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.normal {
|
.normal {
|
||||||
width: 25%;
|
width: 25%;
|
||||||
@@ -30,12 +31,15 @@ $base->debug('UPLOADED FRONT', 'With max size: '.$MAX_UPLOAD_SIZE);
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: red;
|
color: red;
|
||||||
}
|
}
|
||||||
|
.uploadCancel {
|
||||||
|
font-weight: bold;
|
||||||
|
color: orange;
|
||||||
|
}
|
||||||
|
|
||||||
.qq-file-upload-button {
|
.qq-file-upload-button {
|
||||||
border: 1px solid #999999;
|
border: 1px solid #999999;
|
||||||
border-radius: 2px 2px 2px 2px;
|
border-radius: 2px 2px 2px 2px;
|
||||||
box-shadow: 0 10px rgba(255, 255, 255, 0.3) inset, 0 10px rgba(255, 255, 255, 0.2) inset, 0 10px 2px rgba(255, 255, 255, 0.25) inset, 0 -1px 2px rgba(0, 0, 0, 0.3) inset;
|
box-shadow: 0 10px rgba(255, 255, 255, 0.3) inset, 0 10px rgba(255, 255, 255, 0.2) inset, 0 10px 2px rgba(255, 255, 255, 0.25) inset, 0 -1px 2px rgba(0, 0, 0, 0.3) inset;
|
||||||
height: 17px;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 3px 5px 3px;
|
padding: 3px 5px 3px;
|
||||||
background-color: #cacaca;
|
background-color: #cacaca;
|
||||||
@@ -50,102 +54,161 @@ $base->debug('UPLOADED FRONT', 'With max size: '.$MAX_UPLOAD_SIZE);
|
|||||||
border: 1px solid red;
|
border: 1px solid red;
|
||||||
background-color: rgba(80, 80, 80, 0.5);
|
background-color: rgba(80, 80, 80, 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.qq-upload-cancel {
|
||||||
|
border: 1px solid red;
|
||||||
|
border-radius: 2px;
|
||||||
|
text-align: center;
|
||||||
|
padding: 3px 5px 3px;
|
||||||
|
background-color: #eb652d;
|
||||||
|
margin: 2px;
|
||||||
|
}
|
||||||
|
.qq-upload-cancel:hover {
|
||||||
|
background-color: #eb8686;
|
||||||
|
}
|
||||||
|
.qq-upload-cancel:active {
|
||||||
|
border: 1px solid black;
|
||||||
|
background-color: #eb2d2d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progressBarOutside {
|
||||||
|
background-color: #f1f1f1;
|
||||||
|
color: black;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.progressBarInside {
|
||||||
|
background-color: #1e9e84;
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 0.01em;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 0.8em;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
<script src="layout/default/javascript/prototype.js" type="text/javascript"></script>
|
<script src="layout/default/javascript/prototype.js" type="text/javascript"></script>
|
||||||
<script src="layout/default/javascript/file-uploader/fileuploader.js" type="text/javascript"></script>
|
<script src="layout/default/javascript/file-uploader/fileuploader.js" type="text/javascript"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function formatBytes(bytes)
|
function formatBytes(bytes)
|
||||||
{
|
{
|
||||||
var i = -1;
|
var i = -1;
|
||||||
do {
|
do {
|
||||||
bytes = bytes / 1024;
|
bytes = bytes / 1024;
|
||||||
i++;
|
i++;
|
||||||
} while (bytes > 99);
|
} while (bytes > 99);
|
||||||
|
|
||||||
// return Math.max(bytes, 0.1).toFixed(1) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];
|
// return Math.max(bytes, 0.1).toFixed(1) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];
|
||||||
return parseFloat(Math.round(bytes * Math.pow(10, 2)) / Math.pow(10, 2)) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];
|
return parseFloat(Math.round(bytes * Math.pow(10, 2)) / Math.pow(10, 2)) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];
|
||||||
}
|
}
|
||||||
var MAX_UPLOAD_SIZE = <?=$MAX_UPLOAD_SIZE;?>;
|
var MAX_UPLOAD_SIZE = <?=$MAX_UPLOAD_SIZE;?>;
|
||||||
// function to add an AJAX uploadeder to the set
|
// function to add an AJAX uploadeder to the set
|
||||||
function createUploaderSin(divName, divNumber) {
|
function createUploaderSin(divName, divNumber) {
|
||||||
divID = divName + '_' + divNumber;
|
divID = divName + '_' + divNumber;
|
||||||
console.log('Div: %s, Number: %s => ID: %s', divName, divNumber, divID);
|
console.log('Div: %s, Number: %s => ID: %s', divName, divNumber, divID);
|
||||||
|
$(divID + '_Cancel').hide();
|
||||||
var uploader = new qq.FileUploaderBasic({
|
var uploader = new qq.FileUploaderBasic({
|
||||||
// element: document.getElementById(divID),
|
// element: document.getElementById(divID),
|
||||||
element: $(divID),
|
element: $(divID),
|
||||||
action: 'qq_file_upload_ajax.php',
|
cancel: $(divID + '_Cancel'),
|
||||||
multiple: false,
|
action: 'qq_file_upload_ajax.php',
|
||||||
button: $(divID),
|
multiple: false,
|
||||||
allowedExtensions: ['csv', 'zip', 'jpg', 'pdf'],
|
button: $(divID),
|
||||||
sizeLimit: MAX_UPLOAD_SIZE, // size set from php ini
|
allowedExtensions: ['csv', 'zip', 'jpg', 'pdf', 'bz2'],
|
||||||
name: divID,
|
sizeLimit: MAX_UPLOAD_SIZE, // size set from php ini
|
||||||
params: {
|
name: divID,
|
||||||
'file_pos': divNumber, // we need to add here ID or something
|
params: {
|
||||||
'action': 'upload',
|
'file_pos': divNumber, // we need to add here ID or something
|
||||||
'task_uid': divNumber // -> test for some internal uid
|
'action': 'upload',
|
||||||
},
|
'task_uid': divNumber // -> test for some internal uid
|
||||||
onSubmit: function(id, filename, target) {
|
},
|
||||||
console.log('File upload: "%s", ID: "%s" => "%s"', filename, id, target);
|
onSubmit: function(id, filename, target) {
|
||||||
// remove any assigned error classes and flags
|
console.log('File upload: "%s", ID: "%s" => "%s"', filename, id, target);
|
||||||
if ($(target + '_Progress').hasClassName('uploadError'))
|
// remove any assigned error classes and flags
|
||||||
{
|
if ($(target + '_ProgressText').hasClassName('uploadError') || $(target + '_ProgressText').hasClassName('uploadCancel')) {
|
||||||
$(target + '_Progress').className = '';
|
$(target + '_ProgressText').className = '';
|
||||||
$(target + '_Error').value = 0;
|
$(target + '_Error').value = 0;
|
||||||
}
|
}
|
||||||
$(target + '_Progress').innerHTML = 'Start uploading file: ' + filename;
|
$(target + '_ProgressText').innerHTML = 'Start uploading file: ' + filename;
|
||||||
// disabled stuff here
|
$(target + '_Cancel').show();
|
||||||
},
|
// disabled stuff here
|
||||||
onProgress: function(id, filename, loaded, total, target) {
|
},
|
||||||
console.log('Progress for file: "%s", ID: "%s", loaded: "%s", total: "%s" => "%s"', id, filename, loaded, total, target);
|
onProgress: function(id, filename, loaded, total, target) {
|
||||||
var percent = Math.round((loaded / total) * 100);
|
console.log('Progress for file: "%s", ID: "%s", loaded: "%s", total: "%s" => "%s"', id, filename, loaded, total, target);
|
||||||
$(target + '_Progress').innerHTML = 'Uploading: ' + filename + ', ' + percent + '%' + ' (' + formatBytes(loaded) + '/' + formatBytes(total) + ')';
|
var percent = Math.round((loaded / total) * 100);
|
||||||
},
|
$(target + '_ProgressBar').innerHTML = percent + '%';
|
||||||
onComplete: function(id, filename, responseJSON, target) {
|
$(target + '_ProgressBar').style.width = percent + '%';
|
||||||
console.log('File upload for file "%s", id "%s" done with status "%s" => "%s", And success: %s', filename, id, responseJSON, target, responseJSON.result.success);
|
$(target + '_ProgressText').innerHTML = 'Uploading: ' + filename + ', ' + formatBytes(loaded) + '/' + formatBytes(total);
|
||||||
if (responseJSON.result.success)
|
},
|
||||||
{
|
onComplete: function(id, filename, responseJSON, target) {
|
||||||
$(target + '_Progress').innerHTML = 'Uploaded: ' + filename + ' (' + responseJSON.filesize_formated + ')';
|
console.log('File upload for file "%s", id "%s" done with status "%s" => "%s", And success: %s', filename, id, responseJSON, target, responseJSON.result.success);
|
||||||
// also write hidden vars for this (file name, etc)
|
if (responseJSON.result.success) {
|
||||||
// for that we replace the divName part from the target and get just the pos number ?
|
$(target + '_ProgressBar').innerHTML = '100%';
|
||||||
// $(target + 'Name').value = filename;
|
$(target + '_ProgressBar').style.width = '100%';
|
||||||
// $(target + 'NameUpload').value = responseJSON.filename;
|
$(target + '_ProgressText').innerHTML = 'Uploaded: ' + filename + ' (' + responseJSON.filesize_formated + ')';
|
||||||
// $(target + 'Type').value = responseJSON.type;
|
// also write hidden vars for this (file name, etc)
|
||||||
// $(target + 'Size').value = responseJSON.filesize;
|
// for that we replace the divName part from the target and get just the pos number ?
|
||||||
}
|
// $(target + 'Name').value = filename;
|
||||||
else
|
// $(target + 'NameUpload').value = responseJSON.filename;
|
||||||
{
|
// $(target + 'Type').value = responseJSON.type;
|
||||||
// set the error class
|
// $(target + 'Size').value = responseJSON.filesize;
|
||||||
$(target + '_Progress').className = 'uploadError';
|
} else {
|
||||||
// flag error
|
// set the error class
|
||||||
$(target + '_Error').value = 1;
|
$(target + '_ProgressText').className = 'uploadError';
|
||||||
// and write the error
|
// flag error
|
||||||
$(target + '_Progress').innerHTML = 'UPLOAD FAILED FOR FILE: ' + filename;
|
$(target + '_Error').value = 1;
|
||||||
}
|
// and write the error
|
||||||
// renable stuff here
|
$(target + '_ProgressText').innerHTML = 'UPLOAD FAILED FOR FILE: ' + filename;
|
||||||
},
|
}
|
||||||
/*showMessage: function(message) {
|
// renable stuff here
|
||||||
console.log('MESSAGE: %s', message);
|
$(target + '_Cancel').hide();
|
||||||
}, */
|
},
|
||||||
debug: true
|
onCancel: function (id, filename, target) {
|
||||||
});
|
// cancel upload
|
||||||
// console.log('INIT Nr %s => cnt: %s', divNumber, uploader);
|
console.log('File upload cancled for file "%s", id "%s"', filename, id);
|
||||||
return uploader;
|
// upload cancel
|
||||||
}
|
$(target + '_ProgressText').className = 'uploadCancel';
|
||||||
|
$(target + '_Error').value = 1;
|
||||||
|
$(target + '_ProgressText').innerHTML = 'UPLOAD CANCELED FOR FILE: ' + filename;
|
||||||
|
$(target + '_Cancel').hide();
|
||||||
|
},
|
||||||
|
/*showMessage: function(message) {
|
||||||
|
console.log('MESSAGE: %s', message);
|
||||||
|
}, */
|
||||||
|
debug: true
|
||||||
|
});
|
||||||
|
// console.log('INIT Nr %s => cnt: %s', divNumber, uploader);
|
||||||
|
return uploader;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="masterGroup">
|
<div id="masterGroup">
|
||||||
<div>File upload via AJAX</div>
|
<div>File upload via AJAX (MAX SIZE: <?=$base->byteStringFormat($MAX_UPLOAD_SIZE);?>)</div>
|
||||||
<div class="flx-s">
|
<div class="flx-s">
|
||||||
<div id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_MF5tISORiay7" class="normal qq-file-upload-button">Upload File</div>
|
<div id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_MF5tISORiay7" class="normal qq-file-upload-button" style="width: 20%">Upload File</div>
|
||||||
<div id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_MF5tISORiay7_Progress"></div>
|
<div style="width: 5%">
|
||||||
|
<div id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_MF5tISORiay7_Cancel" class="qq-upload-cancel">X</div>
|
||||||
|
</div>
|
||||||
|
<div style="width: 75%; padding: 5px;">
|
||||||
|
<div id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_MF5tISORiay7_ProgressText"></div>
|
||||||
|
<div class="progressBarOutside">
|
||||||
|
<div class="progressBarInside" id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_MF5tISORiay7_ProgressBar" style="width: 0%">0%</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<input type="hidden" name="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_MF5tISORiay7_Error" id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_MF5tISORiay7_Error" value="">
|
<input type="hidden" name="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_MF5tISORiay7_Error" id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_MF5tISORiay7_Error" value="">
|
||||||
</div>
|
</div>
|
||||||
<div class="flx-s">
|
<div class="flx-s">
|
||||||
<div id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_Ww9iWKrl3Xou" class="normal qq-file-upload-button">Upload File</div>
|
<div id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_Ww9iWKrl3Xou" class="normal qq-file-upload-button" style="width: 20%">Upload File</div>
|
||||||
<div id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_Ww9iWKrl3Xou_Progress"></div>
|
<div style="width: 5%">
|
||||||
|
<div id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_Ww9iWKrl3Xou_Cancel" class="qq-upload-cancel">X</div>
|
||||||
|
</div>
|
||||||
|
<div style="width: 75%; padding: 5px;">
|
||||||
|
<div id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_Ww9iWKrl3Xou_ProgressText"></div>
|
||||||
|
<div class="progressBarOutside">
|
||||||
|
<div class="progressBarInside" id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_Ww9iWKrl3Xou_ProgressBar" style="width: 0%">0%</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<input type="hidden" name="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_Ww9iWKrl3Xou_Error" id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_Ww9iWKrl3Xou_Error" value="">
|
<input type="hidden" name="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_Ww9iWKrl3Xou_Error" id="Uploader_3WD7MAFmjAux_dlvvu13tezNj_XeSO0Ovauli0_Ww9iWKrl3Xou_Error" value="">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ require 'config.inc' ;
|
|||||||
DEFINE('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
DEFINE('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||||
$base = new CoreLibs\Basic();
|
$base = new CoreLibs\Basic();
|
||||||
|
|
||||||
|
print "THIS HOST: ".HOST_NAME.", with PROTOCOL: ".HOST_PROTOCOL." is running SSL: ".HOST_SSL."<br>";
|
||||||
|
|
||||||
// $test = array (
|
// $test = array (
|
||||||
// 'A' => array (
|
// 'A' => array (
|
||||||
// 'B' => array (),
|
// 'B' => array (),
|
||||||
@@ -31,6 +33,9 @@ $base->debug('ARRAY', $base->printAr($test));
|
|||||||
|
|
||||||
function rec($pre, $cur, $node = array ())
|
function rec($pre, $cur, $node = array ())
|
||||||
{
|
{
|
||||||
|
if (!is_array($node)) {
|
||||||
|
$node = array ();
|
||||||
|
}
|
||||||
print "<div style='color: green;'>#### PRE: ".$pre.", CUR: ".$cur.", N-c: ".count($node)." [".join('|', array_keys($node))."]</div>";
|
print "<div style='color: green;'>#### PRE: ".$pre.", CUR: ".$cur.", N-c: ".count($node)." [".join('|', array_keys($node))."]</div>";
|
||||||
if (!$pre) {
|
if (!$pre) {
|
||||||
print "** <span style='color: red;'>NEW</span><br>";
|
print "** <span style='color: red;'>NEW</span><br>";
|
||||||
|
|||||||
@@ -301,6 +301,17 @@ function acssel(element, css)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// METHOD: scssel
|
||||||
|
// PARAMS: element, style to remove, style to add
|
||||||
|
// RETURN: "none", in place add because of reference
|
||||||
|
// DESC : removes one css and adds another
|
||||||
|
// is a wrapper around rcssel/acssel
|
||||||
|
function scssel(element, rcss, acss)
|
||||||
|
{
|
||||||
|
rcssel(element, rcss);
|
||||||
|
acssel(element, acss);
|
||||||
|
}
|
||||||
|
|
||||||
// METHOD: phfo [produce html from object]
|
// METHOD: phfo [produce html from object]
|
||||||
// PARAMS: object tree with dom element declarations
|
// PARAMS: object tree with dom element declarations
|
||||||
// RETURN: HTML string that can be used as innerHTML
|
// RETURN: HTML string that can be used as innerHTML
|
||||||
|
|||||||
@@ -275,6 +275,9 @@ qq.FileUploaderBasic = function(o){
|
|||||||
emptyError: "{file} is empty, please select files again without it.",
|
emptyError: "{file} is empty, please select files again without it.",
|
||||||
onLeave: "The files are being uploaded, if you leave now the upload will be cancelled."
|
onLeave: "The files are being uploaded, if you leave now the upload will be cancelled."
|
||||||
},
|
},
|
||||||
|
classes: {
|
||||||
|
cancel: 'qq-upload-cancel'
|
||||||
|
},
|
||||||
showMessage: function(message){
|
showMessage: function(message){
|
||||||
alert(message);
|
alert(message);
|
||||||
}
|
}
|
||||||
@@ -290,6 +293,8 @@ qq.FileUploaderBasic = function(o){
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._preventLeaveInProgress();
|
this._preventLeaveInProgress();
|
||||||
|
this._classes = this._options.classes;
|
||||||
|
this._bindCancelEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
qq.FileUploaderBasic.prototype = {
|
qq.FileUploaderBasic.prototype = {
|
||||||
@@ -364,6 +369,8 @@ qq.FileUploaderBasic.prototype = {
|
|||||||
},
|
},
|
||||||
_onSubmit: function(id, fileName){
|
_onSubmit: function(id, fileName){
|
||||||
this._filesInProgress++;
|
this._filesInProgress++;
|
||||||
|
// get current upload id for cancel
|
||||||
|
this.qqFileId = id;
|
||||||
},
|
},
|
||||||
_onProgress: function(id, fileName, loaded, total){
|
_onProgress: function(id, fileName, loaded, total){
|
||||||
},
|
},
|
||||||
@@ -374,6 +381,7 @@ qq.FileUploaderBasic.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
_onCancel: function(id, fileName){
|
_onCancel: function(id, fileName){
|
||||||
|
// console.log('CORE CANCEL: %s', id);
|
||||||
this._filesInProgress--;
|
this._filesInProgress--;
|
||||||
},
|
},
|
||||||
_onInputChange: function(input){
|
_onInputChange: function(input){
|
||||||
@@ -401,6 +409,7 @@ qq.FileUploaderBasic.prototype = {
|
|||||||
var id = this._handler.add(fileContainer);
|
var id = this._handler.add(fileContainer);
|
||||||
var fileName = this._handler.getName(id);
|
var fileName = this._handler.getName(id);
|
||||||
|
|
||||||
|
// console.log('UPLOAD FILE: %s, FN: %s', id, fileName);
|
||||||
if (this._options.button)
|
if (this._options.button)
|
||||||
{
|
{
|
||||||
if (this._options.onSubmit(id, fileName, this._options.button.id) !== false){
|
if (this._options.onSubmit(id, fileName, this._options.button.id) !== false){
|
||||||
@@ -485,6 +494,24 @@ qq.FileUploaderBasic.prototype = {
|
|||||||
} while (bytes > 99);
|
} while (bytes > 99);
|
||||||
|
|
||||||
return Math.max(bytes, 0.1).toFixed(1) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];
|
return Math.max(bytes, 0.1).toFixed(1) + ['kB', 'MB', 'GB', 'TB', 'PB', 'EB'][i];
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* delegate click event for cancel link
|
||||||
|
**/
|
||||||
|
_bindCancelEvent: function(){
|
||||||
|
var self = this,
|
||||||
|
list = this._options.cancel;
|
||||||
|
qq.attach(list, 'click', function(e){
|
||||||
|
e = e || window.event;
|
||||||
|
var target = e.target || e.srcElement;
|
||||||
|
|
||||||
|
if (qq.hasClass(target, self._classes.cancel)){
|
||||||
|
qq.preventDefault(e);
|
||||||
|
console.log('Item: %s', self.qqFileId);
|
||||||
|
self._handler.cancel(self.qqFileId);
|
||||||
|
console.log('## IN PROGRESS: %s', self.getInProgress());
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -895,7 +922,9 @@ qq.UploadHandlerAbstract.prototype = {
|
|||||||
* Adds file or file input to the queue
|
* Adds file or file input to the queue
|
||||||
* @returns id
|
* @returns id
|
||||||
**/
|
**/
|
||||||
add: function(file){},
|
add: function(file){
|
||||||
|
console.log('FILE: %s', file);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Sends the file identified by id and additional query params to the server
|
* Sends the file identified by id and additional query params to the server
|
||||||
*/
|
*/
|
||||||
@@ -915,6 +944,7 @@ qq.UploadHandlerAbstract.prototype = {
|
|||||||
* Cancels file upload by id
|
* Cancels file upload by id
|
||||||
*/
|
*/
|
||||||
cancel: function(id){
|
cancel: function(id){
|
||||||
|
// console.log('CANCEL: %s', id);
|
||||||
this._cancel(id);
|
this._cancel(id);
|
||||||
this._dequeue(id);
|
this._dequeue(id);
|
||||||
},
|
},
|
||||||
@@ -955,10 +985,11 @@ qq.UploadHandlerAbstract.prototype = {
|
|||||||
*/
|
*/
|
||||||
_dequeue: function(id){
|
_dequeue: function(id){
|
||||||
var i = qq.indexOf(this._queue, id);
|
var i = qq.indexOf(this._queue, id);
|
||||||
|
// console.log('==> Dequeue: %s with %s', id, i);
|
||||||
this._queue.splice(i, 1);
|
this._queue.splice(i, 1);
|
||||||
|
|
||||||
var max = this._options.maxConnections;
|
var max = this._options.maxConnections;
|
||||||
|
// console.log('==> Dequeue next: %s, max: %s', this._queue.length, max);
|
||||||
if (this._queue.length >= max && i < max){
|
if (this._queue.length >= max && i < max){
|
||||||
var nextId = this._queue[max-1];
|
var nextId = this._queue[max-1];
|
||||||
this._upload(nextId, this._params[nextId]);
|
this._upload(nextId, this._params[nextId]);
|
||||||
@@ -998,7 +1029,6 @@ qq.extend(qq.UploadHandlerForm.prototype, {
|
|||||||
},
|
},
|
||||||
_cancel: function(id){
|
_cancel: function(id){
|
||||||
this._options.onCancel(id, this.getName(id));
|
this._options.onCancel(id, this.getName(id));
|
||||||
|
|
||||||
delete this._inputs[id];
|
delete this._inputs[id];
|
||||||
|
|
||||||
var iframe = document.getElementById(id);
|
var iframe = document.getElementById(id);
|
||||||
@@ -1013,7 +1043,7 @@ qq.extend(qq.UploadHandlerForm.prototype, {
|
|||||||
},
|
},
|
||||||
_upload: function(id, params){
|
_upload: function(id, params){
|
||||||
var input = this._inputs[id];
|
var input = this._inputs[id];
|
||||||
// console.log('IFRAME upload: %s', id);
|
// console.log('IFRAME upload: %s', id);
|
||||||
|
|
||||||
if (!input){
|
if (!input){
|
||||||
throw new Error('file with passed id was not added, or already uploaded or cancelled');
|
throw new Error('file with passed id was not added, or already uploaded or cancelled');
|
||||||
@@ -1270,6 +1300,7 @@ qq.extend(qq.UploadHandlerXhr.prototype, {
|
|||||||
this._dequeue(id);
|
this._dequeue(id);
|
||||||
},
|
},
|
||||||
_cancel: function(id){
|
_cancel: function(id){
|
||||||
|
// console.log('CANCEL EXT: %s', id);
|
||||||
this._options.onCancel(id, this.getName(id));
|
this._options.onCancel(id, this.getName(id));
|
||||||
|
|
||||||
this._files[id] = null;
|
this._files[id] = null;
|
||||||
|
|||||||
@@ -101,9 +101,9 @@ class qqFileUploader
|
|||||||
$this->uploadFileExt = $ext;
|
$this->uploadFileExt = $ext;
|
||||||
|
|
||||||
if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) {
|
if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) {
|
||||||
return array('success'=>true);
|
return array('success' => true);
|
||||||
} else {
|
} else {
|
||||||
return array('error'=> 'Could not save uploaded file.' .
|
return array('error' => 'Could not save uploaded file.' .
|
||||||
'The upload was cancelled, or server error encountered');
|
'The upload was cancelled, or server error encountered');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user