blob: 2ff9e9625b911bdb87540ea6622726629199096d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php';
if (!isset($_FILES['file'])) {
http_response_code(400);
exit("No 'file' specified!");
}
if (!is_dir(FILE_DIRECTORY) && !mkdir(FILE_DIRECTORY, 0777, true)) {
http_response_code(500);
exit("Failed to create a directory for user files");
}
$file = $_FILES['file'];
if (!move_uploaded_file($file['tmp_name'], FILE_DIRECTORY . sprintf('/%s', $file['name']))) {
http_response_code(500);
exit("Failed to save the file. Try again later.");
}
header(sprintf('Location: /%s', $file['name']));
|