· 7 years ago · Mar 05, 2018, 10:04 PM
1<?php
2
3$secret_key = "placeholder";
4$sharexdir = "sharex/";
5$domain_url = 'http://placehold.er' //make sure it looks exactly like this with the / at the end
6
7function RandomString() {
8 $key = "";
9 $key .= date("Y-m-d-H-i-s");
10 $characters = '0123456789abcdefghijklmnopqrstuvwxyz';
11 for ($i = 0; $i < 8; $i++) {
12 $key .= $characters[rand(0, 35)];
13 }
14 return $key;
15}
16
17function UR_exists($url){
18 $headers=get_headers($url);
19 return stripos($headers[0],"200 OK")?true:false;
20}
21
22if(isset($_POST['secret']))
23{
24 if($_POST['secret'] == $secret_key)
25 {
26 $target_file = $_FILES["sharex"]["name"];
27 $fileType = pathinfo($target_file, PATHINFO_EXTENSION);
28 while (True)
29 {
30 $filename = RandomString();
31 if (!UR_exists("http://placehold.er/sharex/".$filename.'.'.$fileType))
32 {
33 break;
34 }
35 // else
36 // {
37 // goto meme;
38 // }
39 }
40
41 if (move_uploaded_file($_FILES["sharex"]["tmp_name"], $sharexdir.$filename.'.'.$fileType))
42 {
43 echo $domain_url.$sharexdir.$filename.'.'.$fileType;
44 }
45 else
46 {
47 // meme:
48 http_response_code(400);
49 }
50 }
51 else
52 {
53 // invalid secret
54 http_response_code(400);
55 }
56}
57else
58{
59 // no post data
60 http_response_code(400);
61}
62?>