· 5 years ago · Sep 05, 2020, 07:40 PM
1<?php
2$secret_key = "test"; //Set this as your secret key, to prevent others uploading to your server.
3$sharexdir = ""; //This is your file dir, also the link..
4$domain_url = 'http://kkeoki.dev/ss/';
5$lengthofstring = 8; //Length of the file name
6
7function RandomString($length) {
8 $keys = array_merge(range(0,9), range('a', 'z'));
9
10 $key = '';
11 for($i=0; $i < $length; $i++) {
12 $key .= $keys[mt_rand(0, count($keys) - 1)];
13 }
14 return $key;
15}
16$filename = RandomString($lengthofstring);
17$target_file = $_FILES["sharex"]["name"];
18$fileType = pathinfo($target_file, PATHINFO_EXTENSION);
19
20if (move_uploaded_file($_FILES["sharex"]["tmp_name"], $sharexdir.$filename.'.'.$fileType))
21{
22 echo $domain_url.$sharexdir.$filename.'.'.$fileType;
23}
24 else
25{
26 echo 'File upload failed - CHMOD/Folder doesn\'t exist?';
27}
28?>
29