From 841ee6521e6a9ab62823714c8c6c286ca39720ed Mon Sep 17 00:00:00 2001 From: Malin Lorch Date: Fri, 15 Jul 2022 06:15:40 -0400 Subject: [PATCH] Better detection of upload error Log upload error JS side & return correct response on upload error caused by tmp file permissions error --- tinyfilemanager.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/tinyfilemanager.php b/tinyfilemanager.php index fd73206..23ea1a4 100644 --- a/tinyfilemanager.php +++ b/tinyfilemanager.php @@ -1,4 +1,5 @@ 'success', + 'info' => "file upload successful", + 'fullPath' => $fullPath + ); } else { $response = array ( 'status' => 'error', - 'info' => "failed to open output stream" + 'info' => "failed to open output stream", + 'errorDetails' => error_get_last() ); } + @fclose($in); @fclose($out); @unlink($tmp_name); - $response = array ( - 'status' => 'success', - 'info' => "file upload successful", - 'fullPath' => $fullPath - ); } else { $response = array ( 'status' => 'error', @@ -949,6 +954,7 @@ if (!empty($_FILES) && !FM_READONLY) { + if ($chunkIndex == $chunkTotal - 1) { rename("{$fullPath}.part", $fullPath); } @@ -1295,13 +1301,16 @@ if (isset($_GET['upload']) && !FM_READONLY) { this.on("sending", function (file, xhr, formData) { let _path = (file.fullPath) ? file.fullPath : file.name; document.getElementById("fullpath").value = _path; + xhr.ontimeout = (function() { toast('Error: Server Timeout'); }); + }).on("success", function (res) { let _response = JSON.parse(res.xhr.response); if(_response.status == "error") { + console.log(_response.errorDetails) toast(_response.info); }