Skip to content

Instantly share code, notes, and snippets.

@dhruva81
Last active February 4, 2019 03:46
Show Gist options
  • Select an option

  • Save dhruva81/be197827ca98d19015b501a8a9b0df73 to your computer and use it in GitHub Desktop.

Select an option

Save dhruva81/be197827ca98d19015b501a8a9b0df73 to your computer and use it in GitHub Desktop.
ShareX code to upload cropped images on server
<?php
$secret_key = "9ge9ag99135213tgedavxgfedsaxeg"; //Set this as your secret key, to prevent others uploading to your server.
$sharexdir = "yoyo/"; //This is your file dir, also the link..
$domain_url = 'http://website.com/';
$lengthofstring = 5; //Length of the file name
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($_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.$sharexdir.$filename.'.'.$fileType;
}
else
{
echo 'File upload failed - CHMOD/Folder doesn\'t exist?';
}
}
else
{
echo 'Invalid Secret Key';
}
}
else
{
echo 'No post data recieved';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment