-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
62 lines (52 loc) · 2.4 KB
/
upload.php
File metadata and controls
62 lines (52 loc) · 2.4 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
<?php
const FIREBASE_URL = 'https://confapp-data-sync.firebaseio.com/';
const FILE_FIELD = 'file';
if(isset($_POST['conferenceID']) && isset($_POST['userToken'])) {
if(isset($_FILES[FILE_FIELD])) {
$conferenceID = $_POST['conferenceID'];
$authToken = $_POST['userToken'];
$url = FIREBASE_URL.'conferences/'.urlencode($conferenceID).'/.json?auth='.urlencode($authToken);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$output = curl_exec($ch);
$outputObject = json_decode($output, true);
curl_close($ch);
if($outputObject['error']) {
print($output);
} else {
$destDirectory = 'uploads/'.$conferenceID.'/';
if(isset($_POST['folder'])) {
$destDirectory .= $_POST['folder'].'/';
}
$filenames=array();
if(!is_dir($destDirectory)) {
mkdir($destDirectory, 0777, true);
}
foreach($_FILES[FILE_FIELD]['tmp_name'] as $key => $tmp_name) {
$file_name = strtolower($_FILES[FILE_FIELD]['name'][$key]);
$file_size = $_FILES[FILE_FIELD]['size'][$key];
$file_tmp = $_FILES[FILE_FIELD]['tmp_name'][$key];
$file_type = $_FILES[FILE_FIELD]['type'][$key];
$dest = $destDirectory.$file_name;
move_uploaded_file($file_tmp, $dest);
$fileURL = 'http://'.$_SERVER['HTTP_HOST'];
$urlSegments = explode('/', $_SERVER['REQUEST_URI']);
$fileURL .= join('/', array_slice($urlSegments, 0, -1));
$fileURL .= '/'.$dest;
array_push($filenames, $fileURL);
}
echo json_encode($filenames);
}
} else if(isset($_POST['remove'])) {
$destDirectory = 'uploads/'.$conferenceID.'/';
echo '{"result":"OK"}';
}
} else {
echo '{"error":"Not enough fields set"}';
}
?>