From fb31a148737d7aafbcfcf6d92b269c0e760e7fe0 Mon Sep 17 00:00:00 2001 From: zachlankton Date: Sun, 19 Jul 2020 20:06:47 -0400 Subject: [PATCH] Added Error Message When File Fails to Write (#399) Added error checking and message for when file fails to write on the server side. Before this change if a write failed on the server side it would still present the user with a misleading "Saved Successfully" Message. --- tinyfilemanager.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tinyfilemanager.php b/tinyfilemanager.php index e39039d..5df073f 100644 --- a/tinyfilemanager.php +++ b/tinyfilemanager.php @@ -435,7 +435,12 @@ if (isset($_POST['ajax']) && !FM_READONLY) { $writedata = $_POST['content']; $fd = fopen($file_path, "w"); @fwrite($fd, $writedata); + $write_results = @fwrite($fd, $writedata); fclose($fd); + if ($write_results === false){ + header("HTTP/1.1 500 Internal Server Error"); + die("Could Not Write File! - Check Permissions / Ownership"); + } die(true); } @@ -3743,7 +3748,8 @@ $isStickyNavBar = $sticky_navbar ? 'navbar-fixed' : 'navbar-normal'; contentType: "multipart/form-data-encoded; charset=utf-8", //dataType: "json", success: function(mes){toast("Saved Successfully"); window.onbeforeunload = function() {return}}, - failure: function(mes) {toast("Error: try again");} + failure: function(mes) {toast("Error: try again");}, + error: function(mes) {toast(`

${mes.responseText}

`);} }); }