Document: Change BigUpload when finishing upload and renaming file

pull/4399/head
Angel Fernando Quiroz Campos 3 years ago
parent 2beec7d262
commit 19bed63b77
  1. 37
      main/inc/lib/javascript/bigupload/inc/bigUpload.php
  2. 2
      main/inc/lib/javascript/bigupload/js/bigUpload.js

@ -173,12 +173,26 @@ class BigUploadResponse
/** /**
* Function to rename and move the finished file. * Function to rename and move the finished file.
* *
* @param string $final_name Name to rename the finished upload to
*
* @return string JSON object with result of rename * @return string JSON object with result of rename
*/ */
public function finishUpload($finalName) public function finishUpload()
{ {
$tempName = $this->getTempName();
$sessionBigUpload = ChamiloSession::read('bigupload', []);
if (!isset($sessionBigUpload[$tempName])) {
return json_encode(
[
'errorStatus' => 1,
'errorText' => get_lang('UnableToDeleteTempFile'),
]
);
}
/** @var string $finalName Name to rename the finished upload to */
$finalName = $sessionBigUpload[$tempName];
$origin = $_POST['origin']; $origin = $_POST['origin'];
if ($origin == 'document') { if ($origin == 'document') {
$tmpFile = $this->getTempDirectory().$this->getTempName(); $tmpFile = $this->getTempDirectory().$this->getTempName();
@ -287,6 +301,8 @@ class BigUploadResponse
} }
} }
$sessionBigUpload = ChamiloSession::read('bigupload', []);
//Instantiate the class //Instantiate the class
$bigUpload = new BigUploadResponse(); $bigUpload = new BigUploadResponse();
@ -306,6 +322,13 @@ if (!empty($tempName)) {
$bigUpload->setTempName($tempName); $bigUpload->setTempName($tempName);
if (isset($_GET['name'])) {
$sessionBigUpload[$bigUpload->getTempName()] = disable_dangerous_file(
api_replace_dangerous_char($_GET['name'])
);
ChamiloSession::write('bigupload', $sessionBigUpload);
}
switch ($_GET['action']) { switch ($_GET['action']) {
case 'upload': case 'upload':
print $bigUpload->uploadFile(); print $bigUpload->uploadFile();
@ -314,7 +337,13 @@ switch ($_GET['action']) {
print $bigUpload->abortUpload(); print $bigUpload->abortUpload();
break; break;
case 'finish': case 'finish':
print $bigUpload->finishUpload($_POST['name']); print $bigUpload->finishUpload();
if (isset($sessionBigUpload[$bigUpload->getTempName()])) {
unset($sessionBigUpload[$bigUpload->getTempName()]);
ChamiloSession::write('bigupload', $sessionBigUpload);
}
break; break;
case 'post-unsupported': case 'post-unsupported':
print $bigUpload->postUnsupported(); print $bigUpload->postUnsupported();

@ -175,7 +175,7 @@ function bigUpload () {
//this.uploadData.key is then populated with the filename to use for subsequent requests //this.uploadData.key is then populated with the filename to use for subsequent requests
//When this method sends a valid filename (i.e. key != 0), the server will just append the data being sent to that file. //When this method sends a valid filename (i.e. key != 0), the server will just append the data being sent to that file.
xhr = new XMLHttpRequest(); xhr = new XMLHttpRequest();
xhr.open("POST", parent.settings.scriptPath + '?action=upload&origin=' + parent.settings.origin+'&key=' + parent.uploadData.key, true); xhr.open("POST", parent.settings.scriptPath + '?action=upload' + '&key=' + parent.uploadData.key + (parent.uploadData.key ? '' : '&name=' + parent.uploadData.file.name), true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {

Loading…
Cancel
Save