Last active
October 24, 2019 14:27
-
-
Save 7bitlyrus/a096dfb8a29a4d7f7fca2d53cd1b53a6 to your computer and use it in GitHub Desktop.
Quick & Dirty PHP Custom ShareX Uploader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$users = [ | |
"user1" => "put-the-secret-here", | |
"user2" => "another-secret-here", | |
]; | |
if(isset($_POST['secret'])) { | |
if(in_array($_POST['secret'], $users)) { | |
// $filename = substr(hash("sha256", random_int(0, PHP_INT_MAX) . time()),0,8) . "." . pathinfo($_FILES["f"]["name"], PATHINFO_EXTENSION); | |
$filename = generateRandom(8) . "." . pathinfo($_FILES["f"]["name"], PATHINFO_EXTENSION); | |
if (move_uploaded_file($_FILES["f"]["tmp_name"], $filename)) { | |
echo "http://your.domain.name/" . $filename; | |
file_put_contents("../log.txt", date(DATE_ATOM) . " " . array_search($_POST['secret'], $users) . " " . $filename . "\n", FILE_APPEND | LOCK_EX); | |
} else { | |
header("HTTP/1.0 500 Internal Server Error"); | |
die("Internal Server Error"); | |
} | |
} else { | |
header("HTTP/1.0 403 Forbidden"); | |
die("Forbidden"); | |
} | |
} else { | |
header("HTTP/1.0 400 Bad Request"); | |
die("Bad Request"); | |
} | |
// https://gist.github.com/kburnik/2fcbe7b5105c3533ca7b38e32d46a00f | |
function generateRandom($length = 10, $prefix="") { | |
return $prefix . substr(base_convert(md5(uniqid()), 16, 36), 0, $length); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Name": "your.domain.name", | |
"DestinationType": "None", | |
"RequestType": "POST", | |
"RequestURL": "http://your.domain.name/upload.php", | |
"FileFormName": "f", | |
"Arguments": { | |
"secret": "YOUR-SECRET-HERE" | |
}, | |
"ResponseType": "Text" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment