From 924297975e1730b01d4cd9e50abd6897258932a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jim=20B=C3=A4ckstr=C3=B6m?= Date: Sat, 7 Feb 2015 18:18:17 +0200 Subject: [PATCH] api.php - auto-append extension Added paramater autoext to automatically append file extension to the name parameter supplied. (Useful for example in ShareX, if you want to have a custom filename, since you cannot supply the extension of the uploaded file in the uploader config.) --- api.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api.php b/api.php index 9036270..97779f5 100644 --- a/api.php +++ b/api.php @@ -6,7 +6,13 @@ if(isset($_GET['d'])) { case 'upload': if(!empty($_POST['name'])){ - save_file($_FILES["file"]["tmp_name"], $_POST['name']); + if(isset($_POST['autoext'])){ + $oftheworld = explode(".", $_FILES["file"]["name"]); + $ext = end($oftheworld); + save_file($_FILES["file"]["tmp_name"], $_POST['name'] . $ext); + }else{ + save_file($_FILES["file"]["tmp_name"], $_POST['name']); + } }else{ save_file($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]); }