commit be26efa24afc3a183ce1c2c00b6b9fe2b0f4b828 Author: Fascinated Date: Sun Apr 9 11:58:09 2023 +0100 add php script and uploader for sharex diff --git a/Uploader.sxcu b/Uploader.sxcu new file mode 100644 index 0000000..00809a1 --- /dev/null +++ b/Uploader.sxcu @@ -0,0 +1,13 @@ +{ + "Version": "14.1.0", + "Name": "Uploader", + "DestinationType": "ImageUploader, TextUploader, FileUploader", + "RequestMethod": "POST", + "RequestURL": "https://YOUR_DOMAIN/upload.php", + "Body": "MultipartFormData", + "Arguments": { + "secret": "the secret in the php file" + }, + "FileFormName": "sharex", + "URL": "https://YOUR_DOMAIN/{json:url}" +} \ No newline at end of file diff --git a/upload.php b/upload.php new file mode 100644 index 0000000..d68aead --- /dev/null +++ b/upload.php @@ -0,0 +1,66 @@ + $status, 'url' => $message, 'processingTime' => round($timeTaken, 2) . "ms"); + echo(json_encode($json)); + die(); +} + +$token = $_POST['secret']; +$file = $_FILES['sharex']; + +// Check if the token is valid +if (!checkToken($token)) { + $timeTaken = microtime(true) - $before; + returnJson('ERROR', 'Invalid or missing secret key', $timeTaken); + die(); +} + +// Check if the file was uploaded +if (!isset($file)) { + $timeTaken = microtime(true) - $before; + returnJson('ERROR', 'No file was uploaded', $timeTaken); + die(); +} + +$target_file = $_FILES["sharex"]["name"]; // File name +$fileType = pathinfo($target_file, PATHINFO_EXTENSION); // File extension (e.g. png, jpg, etc.) + +if (in_array($fileType, array("png", "jpeg", "jpg"))) { + // Convert to webp + $image = imagecreatefromstring(file_get_contents($_FILES["sharex"]["tmp_name"])); + $webp_file = pathinfo($target_file, PATHINFO_FILENAME) . ".webp"; + imagewebp($image, $webp_file, 90); + imagedestroy($image); + $target_file = $webp_file; +} + +// Upload the file +if (move_uploaded_file($_FILES["sharex"]["tmp_name"], $target_file)) { + $timeTaken = microtime(true) - $before; + returnJson('OK', $target_file, $timeTaken); +} else { + $timeTaken = microtime(true) - $before; + returnJson('ERROR', 'File upload failed. Does the folder exist and did you CHMOD the folder?', $timeTaken); +} +?> \ No newline at end of file