Skip to content

Instantly share code, notes, and snippets.

@LevitatingBusinessMan
Last active March 15, 2018 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LevitatingBusinessMan/c6a4cab103950548a340b69d5a7d0ce8 to your computer and use it in GitHub Desktop.
Save LevitatingBusinessMan/c6a4cab103950548a340b69d5a7d0ce8 to your computer and use it in GitHub Desktop.
A simple sharex custom upload script
<?php
#No dashes in the end/begin of directory or domain
$key = "key_here";
$file_dir = "i"; #Make sure this does exist already
$nameLength = 5;
$IMGonly = true;
$domain = 'domain_here';
if (isset($_POST['key'])){
if ($_POST['key'] == $key){
if ($IMGonly == true && is_array(getimagesize($_FILES["file"]["tmp_name"])) == true || $IMGonly == false) {
$target = $file_dir.'/'.createID($nameLength).'.'.pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target)){
echo 'https://'.$domain.'/'.$target;
} else {
echo "File upload failed. Does directory ".$file_dir." exist?";
}
} else {
echo "File not accepted!";
}
}else {
echo "key not valid";
}
} else {
echo "No key specified";
}
function createID($length) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment