diff --git a/private/config_template.ini b/private/config_template.ini index f0bafd9..00211db 100644 --- a/private/config_template.ini +++ b/private/config_template.ini @@ -24,7 +24,7 @@ site_title = "Timeline" txt_file_path = "twtxt.txt" ; Path to folder where you want to upload images for your posts -media_upload = "../media" +media_upload = "./media" public_media = "https://example.com/timeline/media" ; Full URL for your public twtxt.txt file diff --git a/views/upload_img.php b/views/upload_img.php index 0cbcce7..603d583 100644 --- a/views/upload_img.php +++ b/views/upload_img.php @@ -26,10 +26,12 @@ $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'])) { - echo "

"; + $msg = "

"; // Configure upload directory and allowed file types $upload_dir = $media_upload.DIRECTORY_SEPARATOR; @@ -63,19 +65,19 @@ if(isset($_POST['submit'])) { // Verify file size - 2MB max if ($file_size > $maxsize) - echo "Error: File size is larger than the allowed limit."; + $msg .= "Error: File size is larger than the allowed limit.
"; // 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)) { - echo "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)) { - // echo "{$file_name} successfully uploaded
"; + // $msg .= "{$file_name} successfully uploaded
"; // } // else { - // echo "Error uploading {$file_name} - File already exists!
"; + // $msg .= "Error uploading {$file_name} - File already exists!
"; // } } else { @@ -86,43 +88,53 @@ if(isset($_POST['submit'])) { $public_file = $public_media.basename($file_path); /* - echo ''; - echo ''; + $msg .= '
'; - echo ''; - echo '
'; + $msg .= ''; //$file = str_replace('../', $base_url, $file); - echo ''; - echo '
'; + $msg .= ''; + $msg .= '![]('.$public_file.')
'; + $msg .= '![]('.$public_file.')'; + $msg .= ''; */ - echo "{$file_name} successfully uploaded
"; - //echo ""; - //echo "![]({$full_url})
"; - //echo ""; + $msg .= "{$file_name} successfully uploaded
"; + //$msg .= ""; + //$msg .= "![]({$full_url})
"; + //$msg .= ""; } else { - echo "Error uploading {$file_name}
"; + $msg .= "Error uploading {$file_name}
"; } } } else { // If file extension not valid - echo '

'; - echo "Error uploading {$file_name} for unknown reason"; - echo "({$file_ext} file type is not allowed)
"; - echo '

'; + //$msg .= '

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

'; } } } else { // If no files selected - echo "No files selected."; + $msg .= "No files selected.
"; } - echo "

"; + $msg .= "

"; + + $_SESSION["message"] = $msg; + header('Location: '.$_SERVER['REQUEST_URI']); + exit; +} + +// Show message store in session +if (isset($_SESSION["message"])) { + echo $_SESSION["message"]; + unset($_SESSION["message"]); } diff --git a/views/upload_img_w3c.php b/views/upload_img_old.php similarity index 100% rename from views/upload_img_w3c.php rename to views/upload_img_old.php