Skip to content

Instantly share code, notes, and snippets.

@ParadauxIO
Created January 17, 2021 02:30
Show Gist options
  • Save ParadauxIO/f618350cdcce1a059158c561f66c54e8 to your computer and use it in GitHub Desktop.
Save ParadauxIO/f618350cdcce1a059158c561f66c54e8 to your computer and use it in GitHub Desktop.
ShareX Custom Uploader | Requires write access to the directory it's sending your content to
<?php
error_reporting(E_ERROR);
$tokens = array("somepassword", "someotherpassword"); //Tokens go here
$sharexdir = "img/";
$lengthofstring = 5;
function RandomString($length) {
$keys = array_merge(range(0,9), range('a', 'z'));
for($i=0; $i < $length; $i++) {
$key .= $keys[mt_rand(0, count($keys) - 1)];
}
return $key;
}
if(isset($_POST['secret']))
{
if(in_array($_POST['secret'], $tokens))
{
$filename = RandomString($lengthofstring);
$target_file = $_FILES["sharex"]["name"];
$fileType = pathinfo($target_file, PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES["sharex"]["tmp_name"], $sharexdir.$filename.'.'.$fileType))
{
$json->status = "OK";
$json->errormsg = "";
$json->url = $filename . '.' . $fileType;
}
else
{
echo 'File upload failed - CHMOD/Folder doesn\'t exist?';
}
}
else
{
echo 'Invalid Secret Key';
}
}
else
{
echo 'No post data recieved';
}
echo(json_encode($json));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment