mirror of
https://github.com/prasathmani/tinyfilemanager
synced 2024-06-09 01:12:16 +02:00
Better detection of upload error
Log upload error JS side & return correct response on upload error caused by tmp file permissions error
This commit is contained in:
parent
a65f8ff8b5
commit
841ee6521e
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
//Default Configuration
|
//Default Configuration
|
||||||
$CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"calc_folder":false,"theme":"light"}';
|
$CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"calc_folder":false,"theme":"light"}';
|
||||||
|
|
||||||
|
@ -868,6 +869,7 @@ if (isset($_GET['dl'])) {
|
||||||
|
|
||||||
// Upload
|
// Upload
|
||||||
if (!empty($_FILES) && !FM_READONLY) {
|
if (!empty($_FILES) && !FM_READONLY) {
|
||||||
|
|
||||||
$override_file_name = false;
|
$override_file_name = false;
|
||||||
$chunkIndex = $_POST['dzchunkindex'];
|
$chunkIndex = $_POST['dzchunkindex'];
|
||||||
$chunkTotal = $_POST['dztotalchunkcount'];
|
$chunkTotal = $_POST['dztotalchunkcount'];
|
||||||
|
@ -925,21 +927,24 @@ if (!empty($_FILES) && !FM_READONLY) {
|
||||||
$in = @fopen($tmp_name, "rb");
|
$in = @fopen($tmp_name, "rb");
|
||||||
if ($in) {
|
if ($in) {
|
||||||
while ($buff = fread($in, 4096)) { fwrite($out, $buff); }
|
while ($buff = fread($in, 4096)) { fwrite($out, $buff); }
|
||||||
|
|
||||||
|
$response = array (
|
||||||
|
'status' => 'success',
|
||||||
|
'info' => "file upload successful",
|
||||||
|
'fullPath' => $fullPath
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$response = array (
|
$response = array (
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
'info' => "failed to open output stream"
|
'info' => "failed to open output stream",
|
||||||
|
'errorDetails' => error_get_last()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@fclose($in);
|
@fclose($in);
|
||||||
@fclose($out);
|
@fclose($out);
|
||||||
@unlink($tmp_name);
|
@unlink($tmp_name);
|
||||||
|
|
||||||
$response = array (
|
|
||||||
'status' => 'success',
|
|
||||||
'info' => "file upload successful",
|
|
||||||
'fullPath' => $fullPath
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
$response = array (
|
$response = array (
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
|
@ -949,6 +954,7 @@ if (!empty($_FILES) && !FM_READONLY) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ($chunkIndex == $chunkTotal - 1) {
|
if ($chunkIndex == $chunkTotal - 1) {
|
||||||
rename("{$fullPath}.part", $fullPath);
|
rename("{$fullPath}.part", $fullPath);
|
||||||
}
|
}
|
||||||
|
@ -1295,13 +1301,16 @@ if (isset($_GET['upload']) && !FM_READONLY) {
|
||||||
this.on("sending", function (file, xhr, formData) {
|
this.on("sending", function (file, xhr, formData) {
|
||||||
let _path = (file.fullPath) ? file.fullPath : file.name;
|
let _path = (file.fullPath) ? file.fullPath : file.name;
|
||||||
document.getElementById("fullpath").value = _path;
|
document.getElementById("fullpath").value = _path;
|
||||||
|
|
||||||
xhr.ontimeout = (function() {
|
xhr.ontimeout = (function() {
|
||||||
toast('Error: Server Timeout');
|
toast('Error: Server Timeout');
|
||||||
});
|
});
|
||||||
|
|
||||||
}).on("success", function (res) {
|
}).on("success", function (res) {
|
||||||
let _response = JSON.parse(res.xhr.response);
|
let _response = JSON.parse(res.xhr.response);
|
||||||
|
|
||||||
if(_response.status == "error") {
|
if(_response.status == "error") {
|
||||||
|
console.log(_response.errorDetails)
|
||||||
toast(_response.info);
|
toast(_response.info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue