Skip to content

Instantly share code, notes, and snippets.

@Scarsz
Last active April 21, 2018 21:20
Show Gist options
  • Save Scarsz/93d3f9918f5b49fce8c2ee1ecb4256bc to your computer and use it in GitHub Desktop.
Save Scarsz/93d3f9918f5b49fce8c2ee1ecb4256bc to your computer and use it in GitHub Desktop.
Simple custom ShareX destination script
<?php
//
// instructions:
// 1. upload script as "upload.php" (changable, just change the other one too)
// 2. change secret key to something random & unguessable
// 3. ensure the files dir exists and is writable to by the web server
// 4. create a new custom destination on ShareX
// - request url: https://example.com/upload.php
// - file form name: d
// - arguments:
// - name: k
// value: secret key
// 5. make sure your php settings are allowing large max upload sizes
// 6. test & enjoy
//
$domainUrl = 'https://example.com/'; // base domain
$fileDir = "files/"; // files dir
$fileNameLength = 5; // length of randomly generated file names
$secretKey = "SUPERDUPERSECRETKEYDONTTELLANYONEPLS"; // secret key
function RandomString($length) {
$keys = array_merge(range(0,9), range('a', 'z'));
$key = "";
for ($i=0; $i < $length; $i++) {
$key .= $keys[mt_rand(0, count($keys) - 1)];
}
return $key;
}
if (isset($_POST['k'])) {
if ($_POST['k'] == $secretKey) {
$filename = RandomString($fileNameLength);
$target_file = $_FILES["d"]["name"];
$fileType = pathinfo($target_file, PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES["d"]["tmp_name"], $fileDir.$filename.'.'.$fileType)) {
echo $domainUrl.$fileDir.$filename.'.'.$fileType;
} else {
echo 'File upload failed';
}
} else {
echo 'Invalid secret';
}
} else {
echo 'No post data recieved';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment