Skip to content

Instantly share code, notes, and snippets.

@domkirby
Last active September 5, 2022 09:22
Show Gist options
  • Save domkirby/2125be231e65ae2d3f8f5fae1796851e to your computer and use it in GitHub Desktop.
Save domkirby/2125be231e65ae2d3f8f5fae1796851e to your computer and use it in GitHub Desktop.
ShareX Uploader PHP script
<?php
/*
Sharex php upload
INSTALLATION:
-Fill out $secret_key, $sharexdir (or leave blank), and $domain_url
-Upload this to the root for the selected domain
-Configure ShareX Custom Uploader: https://i.imgur.com/y4WHMTH.png (to get to that menu: https://i.imgur.com/psMj84t.png)
By: domkirby and arturtyk
*/
$secret_key = "this is your secret to prevent uploaders you don't know from uploading, generate a random password for this"; //Set this as your secret key, to prevent others uploading to your server.
$sharexdir = ""; //This is your file dir, also the link.. Leave blank to upload the root
$domain_url = 'https://your.server.tld'; //the root domain of your upload URL, include http(s):// (use https like a grownup, this shit is free)
/*
This function generates a file name based on the following:
-The hex encoding of 4 random bytes pulled from the server
-A time based uniqid (similar to a uuid but for PHP), to prevent name collision
*/
function RandomString($length) {
$random = random_bytes(4);
$rHex = bin2hex($random);
$Uniqid = uniqid($rHex,false);
return $Uniqid;
}
if(isset($_POST['secret']))
{
if($_POST['secret'] == $secret_key)
{
$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))
{
echo $domain_url.'/'.$filename.'.'.$fileType;
}
else
{
echo 'File upload failed - CHMOD/Folder doesn\'t exist?';
}
}
else
{
header("HTTP/1.1 401 Unauthorized");
echo 'Invalid Secret Key';
}
}
else
{
header("HTTP/1.1 400 Bad Request");
echo 'No post data recieved';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment