-
Notifications
You must be signed in to change notification settings - Fork 0
/
up.php
50 lines (45 loc) · 1.5 KB
/
up.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
// Original script by: https://nextgenupdate.com/forums/computers/886853-how-make-your-own-custom-sharex-image-uploader-custom-domain-etc.html
// Script was modified so that it works with my website
// SECRET_KEY needs to be in an env file
// For any help with this script please refer to the original post
$env = parse_ini_file('.env');
$secret_key = $env["SECRET_KEY"]; //Set this as your secret key, to prevent others uploading to your server.
$sharexdir = "img/"; //This is your file dir, also the link..
$domain_url = 'https://callum.christmas/'; //Add an S at the end of HTTP if you have a SSL certificate.
$lengthofstring = 5; //Length of the file name
$viewer = "viewer.php?id=";
function RandomString($length) {
$keys = array_merge(range(0,9), range('a', 'z'));
$key = '';
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.$viewer.$filename;
}
else
{
echo 'File upload failed - CHMOD/Folder doesn\'t exist?';
}
}
else
{
echo 'Invalid Secret Key';
}
}
else
{
echo 'No post data recieved';
}
?>