-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
69 lines (58 loc) · 1.54 KB
/
upload.php
File metadata and controls
69 lines (58 loc) · 1.54 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
function output ($data = []) {
echo json_encode($data);
}
/**
* Setters
*/
/**
* The directory in which the files will be moved to
*/
$OUTPUT_DIRECTORY = "images/";
/**
* The domain URL to send back in the response
*/
$DOMAN_URL = 'http://localhost/cdn/';
/**
* New file name
*/
$filename = md5(time());
/**
* If no files were received in the request
*/
if (!count($_FILES)) {
return output([
'success' => false,
'error' => 'No files were sent to be processed'
]);
}
/**
* Get the uploaded file
*/
$uploadedFile = $_FILES["files"]["name"][0];
/**
* Get the extension from the file
*/
$fileType = pathinfo($uploadedFile, PATHINFO_EXTENSION);
/**
* Move the file to the new location with the new name
*/
if (move_uploaded_file($_FILES["files"]["tmp_name"][0], __DIR__ . '/' . $OUTPUT_DIRECTORY . $filename. '.' .$fileType)) {
return output([
'attachments' => [
[
'url' => $DOMAN_URL . $OUTPUT_DIRECTORY . $filename . '.' . $fileType,
'proxy_url' => $DOMAN_URL . $OUTPUT_DIRECTORY . $filename . '.' . $fileType
]
]
]);
/**
* If an error occurred during the move file process
*/
} else {
return output([
'success' => false,
'error' => 'No files were sent to be processed'
]);
}
?>