From 52668f35d46206632985ac190d66ada32119f160 Mon Sep 17 00:00:00 2001 From: Jaidyn Lev Date: Sat, 7 Apr 2018 20:40:17 -0500 Subject: [PATCH] Renaming files now auto-adds file-extensions --- README.md | 2 +- beam.php | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d75e797..971e174 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[!insert-coin](https://coinsh.red/p/logo.png) +![insert-coin](https://coinsh.red/p/logo-big.png) insert-coin's a lightweight & simple image-uploading/URL-shortening service. diff --git a/beam.php b/beam.php index e952a76..10c948d 100644 --- a/beam.php +++ b/beam.php @@ -11,8 +11,15 @@ echo("\n
\n"); if (!empty($_POST["desired_filename"])) { $file_name = $_POST["desired_filename"]; - $file_name = sanitize_filename($file_name); - $dest_file = $file_beam_dir . $file_name; + + if (!pathinfo($file_name, PATHINFO_EXTENSION)) + { + $file_name = $file_name . "." . + (pathinfo($_FILES["fileToUpload"]["name"], + PATHINFO_EXTENSION)); + } + + echo($file_name); $beaming_permitted = 0; } @@ -29,6 +36,9 @@ else $beaming_permitted = 1; } +$file_name = sanitize_filename($file_name); +$dest_file = $file_beam_dir . $file_name; + if (file_exists($dest_file)) { $beaming_permitted = 2;