Post-redirect-get for new_twt

This commit is contained in:
sørenpeter 2025-02-23 21:03:26 +01:00
parent eb6aa2aad7
commit c6cbed680f
2 changed files with 14 additions and 8 deletions

View file

@ -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("<p class='notice'>twtxt.txt file does not exist. Check your <code>config.ini</code></p>");
$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";

View file

@ -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 = "<p class='notice'>";
@ -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! <br>";
$msg .= "Error uploading <strong>{$file_name}</strong> - File already exists! <br>";
// $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 .= '<p class="warning">';
$msg .= "Error uploading {$file_name} for unknown reason";
$msg .= "Error uploading <strong>{$file_name}</strong> for unknown reason";
$msg .= "({$file_ext} file type is not allowed)<br>";
//$msg .= '</p>';
}