From c6cbed680f3d424cf709742db13117fb5cd4752e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?s=C3=B8renpeter?= Date: Sun, 23 Feb 2025 21:03:26 +0100 Subject: [PATCH] Post-redirect-get for new_twt --- views/new_twt.php | 16 ++++++++++++---- views/upload_img.php | 6 ++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/views/new_twt.php b/views/new_twt.php index ca80a5b..cf9a069 100644 --- a/views/new_twt.php +++ b/views/new_twt.php @@ -17,6 +17,8 @@ $public_txt_url = $config['public_txt_url']; $timezone = $config['timezone']; require_once 'libs/load_timezone.php'; +//session_start(); // Post-Redirect-Get Pattern based on: https://icodemag.com/prg-pattern-in-php-what-why-and-how/ + if (isset($_POST['submit'])) { $new_post = filter_input(INPUT_POST, 'new_post'); $new_post = trim($new_post); @@ -31,10 +33,12 @@ if (isset($_POST['submit'])) { // Check if we have a point to insert the next Twt define('NEW_TWT_MARKER', "#~~~#\n"); - if (!file_exists($txt_file_path)) { - echo 'twtxt.txt file does not exist. Check your config.'; - exit; - } + // if (!file_exists($txt_file_path)) { + // echo ''; + // exit; + // } + + if(!file_exists($txt_file_path)) exit("

twtxt.txt file does not exist. Check your config.ini

"); $contents = file_get_contents($txt_file_path); @@ -77,6 +81,10 @@ if (isset($_POST['submit'])) { //header("Location: refresh?url=".$public_txt_url); // Trying to fix issue with douple posting //exit; + //$_SESSION["message"] = $msg; + header('Location: '.$_SERVER['QUERY_STRING']); + exit; + } else { require_once "partials/base.php"; $title = "New post - $title"; diff --git a/views/upload_img.php b/views/upload_img.php index 603d583..e2047b7 100644 --- a/views/upload_img.php +++ b/views/upload_img.php @@ -27,8 +27,6 @@ $media_upload = getcwd() . "/" . $config["media_upload"] . "/"; // Credits: https://www.geeksforgeeks.org/how-to-select-and-upload-multiple-files-with-html-and-php-using-http-post/ session_start(); // Post-Redirect-Get Pattern based on: https://icodemag.com/prg-pattern-in-php-what-why-and-how/ - -// Check if form was submitted if(isset($_POST['submit'])) { $msg = "

"; @@ -70,7 +68,7 @@ if(isset($_POST['submit'])) { // If file with name already exists then append time in // front of name of the file to avoid overwriting of file if(file_exists($file_path)) { - $msg .= "Error uploading {$file_name} - File already exists!
"; + $msg .= "Error uploading {$file_name} - File already exists!
"; // $file_path = $upload_dir.date('Y-m-d_').$file_name; // if( move_uploaded_file($file_tmpname, $file_path)) { @@ -112,7 +110,7 @@ if(isset($_POST['submit'])) { // If file extension not valid //$msg .= '

'; - $msg .= "Error uploading {$file_name} for unknown reason"; + $msg .= "Error uploading {$file_name} for unknown reason"; $msg .= "({$file_ext} file type is not allowed)
"; //$msg .= '

'; }