-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
50 lines (42 loc) · 1.18 KB
/
upload.php
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
<?php
include './config.php';
$form = $_POST;
$type = "buckets";
if(isset($form['type']) && !empty($form['type'])) {
$type = $form['type'];
}
if($type == "buckets") {
$dirPath = 'files/storage';
}else {
$dirPath = 'files/hosting';
}
$folderName = '';
$wrappedDirectory = 'dirr';
$wrapWithDirectory = !empty($wrappedDirectory);
$files = array_diff(scandir($dirPath), array('.', '..'));
$uploadData = [];
foreach ($files as $file) {
$filePath = $dirPath . '/' . $file;
if (is_file($filePath)) {
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->file($filePath);
$uploadData[] = [
'fileName' => $file,
'contentType' => $mimeType,
'filePath' => $filePath
];
}
}
if (!empty($uploadData)) {
$response = uploadToBucket($type, $uploadData, $folderName);
echo json_encode($response, JSON_PRETTY_PRINT);
}else {
echo json_encode([
'status' => 0,
'status_code' => 422,
'message' => "No files to upload, make sure the files folder is filled with something",
"info_error" => 'Failed to upload the file.',
'data' => null
], JSON_PRETTY_PRINT);
die;
}