-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupload.php
More file actions
executable file
·78 lines (72 loc) · 2.77 KB
/
upload.php
File metadata and controls
executable file
·78 lines (72 loc) · 2.77 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
70
71
72
73
74
75
76
77
78
<?php
// Load the config
require_once ('./.config.php');
$message = '';
// Check whether we need to register the user first.
if (($_POST["login"])=='register') {
$registration_fields = array(
'username'=>urlencode($_POST["username"]),
'password'=>urlencode($_POST["password"]),
'email'=>$_POST["email"],
'name'=>urlencode($_POST["name"]),
);
$fields_string = http_build_query($registration_fields);
$url = 'https://api.cyclestreets.net/v2/user.create?key=' . $config['registeredapikey'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec ($ch);
curl_close ($ch);
// Process the result, and show any error
$result = json_decode ($response, true);
if (!$result) {
$photo_url = '/location/#-1/' . rawurlencode('Problem creating new user account - please try again later.');
header("Location: $photo_url");
return;
}
if (isSet ($result['error'])) {
$photo_url = '/location/#-1/' . rawurlencode($result['error']);
header("Location: $photo_url");
return;
} else {
$message = $result['successmessage'];
// Carry on below
}
}
if ($_FILES["mediaupload"]["error"] > 0) {
$message = "File error: " . $_FILES["mediaupload"]["error"];
$photo_url = '/location/#-1/' . rawurlencode($message);
header("Location: $photo_url");
} else {
$file = $_FILES['mediaupload'];
$file_field="@$file[tmp_name]";
$fields = array(
'mediaupload'=>$file_field,
'username'=>urlencode($_POST["username"]),
'password'=>urlencode($_POST["password"]),
'category'=>urlencode($_POST["category"]),
'metacategory'=>urlencode($_POST["metacategory"]),
'caption'=>($_POST["description"])
);
$fields_string = http_build_query($fields);
$url = 'https://api.cyclestreets.net/v2/photomap.add?key=' . $config['registeredapikey'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$result = json_decode($response, true);
if (isset($result['error'])) {
$message = $result['error'];
$photo_url = '/location/#-1/' . rawurlencode('The image could not be uploaded because: ' . $message);
} else {
$photo_id = $result['id'];
$photo_url = '/location/#' . rawurlencode($photo_id) . '/' . rawurlencode('Thank you - the photo has been successfully uploaded:');
}
header("Location: $photo_url");
}
?>