Merge pull request #24018 from Hystepik/develop#1

New : Test of big upload on test_forms
This commit is contained in:
Laurent Destailleur 2023-02-24 17:58:54 +01:00 committed by GitHub
commit 886cab41f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 79 additions and 3 deletions

View File

@ -62,13 +62,19 @@ $flowTotalSize = GETPOST('flowTotalSize', 'alpha');
top_httphead();
dol_syslog(join(',', $_GET));
$result = true;
$result = false;
if (!empty($upload_dir)) {
$temp_dir = $upload_dir.'/'.$flowIdentifier;
} else {
$temp_dir = DOL_DATA_ROOT.'/'.$module.'/temp/'.$flowIdentifier;
$upload_dir = $temp_dir;
$upload_dir = DOL_DATA_ROOT.'/'.$module.'/temp/';
}
if ($module != "test" && !isModEnabled($module)) {
echo json_encode("The module ".$module." is not enabled");
header("HTTP/1.0 400");
die();
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
@ -83,6 +89,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (file_exists($upload_dir.'/'.$flowFilename)) {
echo json_encode('File '.$flowIdentifier.' was already uploaded');
header("HTTP/1.0 200 Ok");
die();
} elseif (!empty($_FILES)) foreach ($_FILES as $file) {
// check the error status
if ($file['error'] != 0) {
@ -133,7 +140,7 @@ function createFileFromChunks($temp_dir, $upload_dir, $fileName, $chunkSize, $to
$total_files = 0;
$files = dol_dir_list($temp_dir, 'files');
foreach ($files as $file) {
if (stripos($file, $fileName) !== false) {
if (stripos($file["name"], $fileName) !== false) {
$total_files++;
}
}

View File

@ -105,6 +105,75 @@ $array = array(1=>'Value 1', 2=>'Value 2', 3=>'Value 3');
$arrayselected = array(1, 3);
print $form->multiselectarray('testmulti', $array, $arrayselected, '', 0, 'minwidth100');
print '<br><br>'."\n";
// Test6a: Upload of big files
print "Test 6a: Upload of big files<br>\n";
print "The file will be uploaded in the directory: documents/test/temp/<br>\n";
if (is_file(DOL_DOCUMENT_ROOT.'/includes/flowjs/flow.js')) {
print '<button id="buttonbigupload" type="button">Browse...</button>';
print '&nbsp;<span id="filespan">No file selected.</span>';
print '<br><div class="progress-bar filepgbar taligncenter" role="progressbar" style="width:1%;display:none"><span class="small valigntop">0%</span></div>';
print '<br><button type="button" style="display:none;" data-fileidentifier="" class="btn green-haze btn-circle cancelfileinput" id="filecancel">Cancel</button>';
print '<script src="'.DOL_URL_ROOT.'/includes/flowjs/flow.js"></script>';
print '<script>
jQuery(document).ready(function() {
var flow = new Flow({
target:"'.DOL_URL_ROOT.'/core/ajax/flowjs-server.php",
query:{module:"test", token:"'.newToken().'"},
testChunks:false
});
';
print 'if(flow.support){
flow.assignBrowse(document.getElementById("buttonbigupload"));
flow.on("fileAdded", function(file, event){
console.log("Trigger event file added", file, event);
$("#filespan").text(file.name);
$("#filecancel").data("fileidentifier", file.uniqueIdentifier)
$("#filecancel").show()
$(".filepgbar").show();
$(".filepgbar").attr("id",file.uniqueIdentifier+"pgbar")
});
flow.on("filesSubmitted", function(array,message){
console.log("Trigger event file submitted");
flow.upload()
});
flow.on("progress", function(){
console.log("progress",flow.files);
flow.files.forEach(function(element){
console.log(element.progress());
width = Math.round(element.progress()*100)
width = width.toString()
$("#"+element.uniqueIdentifier+"pgbar").width(width+"%")
$("#"+element.uniqueIdentifier+"pgbar").children("span").text(width+"%")
});
});
flow.on("fileSuccess", function(file,message){
console.log("The file has been uploaded successfully",file,message);
});
$(".cancelfileinput").on("click", function(){
filename = $(this).data("fileidentifier");
file = flow.getFromUniqueIdentifier(filename);
file.cancel();
$("#"+file.uniqueIdentifier+"pgbar").hide();
console.log("We remove file "+filename);
$("#filespan").text("No file selected.");
$(this).hide();
})
flow.on("fileError", function(file, message){
console.log("Error on file upload",file, message);
$("#"+file.uniqueIdentifier+"pgbar").width(20+"%");
$("#"+file.uniqueIdentifier+"pgbar").children("span").text("ERROR UPLOAD");
});
}
})
';
print '</script>';
} else {
print "If this message displays, please add flow.js and flow.min.js files which can be found here: https://github.com/flowjs/flow.js and place the js lib in htdocs/includes/flowjs/<br>\n";
}
print '</div>';
// End of page