pub / pastesrv

Paste service setup for paste.jayvii.de
git clone https://src.jayvii.de/pub/pastesrv.git
Home | Log | Files | Exports | Refs | README | RSS

commit b3b1d6550e11f7a66de1c984b2a7bd1647e789fd
parent ddd0413aa9c5871c2b225a230da7d35e1f581dae
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Tue, 13 Aug 2024 18:25:57 +0200

feat: allow direct pasting into a textbox

Diffstat:
Mindex.php | 53++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 44 insertions(+), 9 deletions(-)

diff --git a/index.php b/index.php @@ -43,31 +43,64 @@ ?> <!-- Uploader --> - <section id="upload"> - <h2>Upload File</h2> + <section id="paste"> + <h2>Paste Text or Upload file</h2> <p> - You may also upload a file here directly + You may also upload a file here directly or paste text in the textbox + below instead. </p> <form - action="<?php echo "/?auth=" . $_GET["auth"] . "#upload"; ?>" + action="<?php echo "/?auth=" . $_GET["auth"] . "#paste"; ?>" target="_self" method="post" enctype="multipart/form-data" > - <input name="file" type="file" style="width:100%;" class="button"> + <input + name="file" + type="file" + style="width:100%;" + class="button" + > + <textarea + name="text" + style="width:100%;" + autofocus + placeholder="Insert Text you want to paste" + wrap="soft" + ></textarea> <input type="submit" value="Paste!"> </form> <?php /* Process file if available */ - if (!is_null($_FILES["file"]["tmp_name"])) { + if (!is_null($_FILES["file"]["tmp_name"]) || $_POST["text"] != "") { /* Create Hash Name */ $hash = hash("sha256", time()); + $pasted = false; + + /* Process if file was uploaded */ + if (!is_null($_FILES["file"]["tmp_name"])) { + + /* Move file to designated place */ + $pasted = move_uploaded_file( + $_FILES["file"]["tmp_name"], + "./" . $hash + ); - /* Move file to designated place */ - move_uploaded_file($_FILES["file"]["tmp_name"], "./" . $hash); + } + + /* Process if text was given */ + if ($_POST["text"] != "") { + $pasted = file_put_contents( + "./" . $hash, + $_POST["text"] + ); + $pasted = $pasted > 0; + } + + if ($pasted) { ?> @@ -80,7 +113,9 @@ <?php - } /* File exists */ + } /* Pasting was successful */ + + } /* File was uploaded or text input was given */ } /* Auth is correct */