forked from davidcann/deepDropUpload
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathupload.php
More file actions
27 lines (22 loc) · 676 Bytes
/
upload.php
File metadata and controls
27 lines (22 loc) · 676 Bytes
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
<?
// saving uploads is disabled for demo purposes
exit();
$headers = getallheaders();
$file = new stdClass;
$file->name = basename($headers['X-File-Name']);
$file->size = $headers['X-File-Size'];
$file->content = file_get_contents("php://input");
// if everything is ok, save the file somewhere
$storage = "/uploads/";
if (file_exists($storage)) {
$extension = end(explode(".", $file->name));
$unique = rand(1000000000,9999999999) .".". $extension;
while (file_exists($storage . $unique)) {
$unique = rand(1000000000,9999999999) .".". $extension;
}
$path = $storage . $unique;
$handle = fopen($path, 'w');
fwrite($handle, $file->content);
fclose($handle);
}
?>