1
|
<?php
|
2
|
|
3
|
require_once('class/FormValidator.class.php');
|
4
|
require_once('class/site_point.class.php');
|
5
|
require_once('class/utils.class.php');
|
6
|
require_once('constants.inc.php');
|
7
|
|
8
|
class UploadReceiveError extends Exception {}
|
9
|
|
10
|
|
11
|
|
12
|
function handle_upload() {
|
13
|
$upload_messages = array(
|
14
|
UPLOAD_ERR_NO_FILE => 'pas de fichier envoyé',
|
15
|
UPLOAD_ERR_INI_SIZE => 'fichier trop gros',
|
16
|
UPLOAD_ERR_FORM_SIZE => 'fichier trop gros',
|
17
|
);
|
18
|
|
19
|
if (! is_dir(UPLOAD_PATH)) {
|
20
|
if (! mkdir(UPLOAD_PATH)) {
|
21
|
throw new UploadReceiveError(
|
22
|
'Dossier "'.UPLOAD_PATH.'" non inscriptible ou inexistant.');
|
23
|
}
|
24
|
}
|
25
|
foreach ($_FILES['files']['name'] as $i => $file) {
|
26
|
$file_err = $_FILES['files']['error'][$i];
|
27
|
$file_tmp = $_FILES['files']['tmp_name'][$i];
|
28
|
$file_finalpath = utils::get_unique_filepath(UPLOAD_PATH.'/'.basename($file));
|
29
|
|
30
|
if(!empty($file)) {
|
31
|
if(isset($file) && UPLOAD_ERR_OK === $file_err) {
|
32
|
move_uploaded_file($file_tmp, $file_finalpath);
|
33
|
return $file_finalpath;
|
34
|
} else {
|
35
|
throw new UploadReceiveError(
|
36
|
'Une erreur interne a empêché l\'envoi de l\'image :'. $upload_messages[$file_err]);
|
37
|
}
|
38
|
} else {
|
39
|
throw new UploadReceiveError(
|
40
|
'Veuillez passer par le formulaire svp !');
|
41
|
}
|
42
|
}
|
43
|
}
|
44
|
|
45
|
function existant_and_set($list, $keys) {
|
46
|
|
47
|
|
48
|
|
49
|
foreach($keys as $key) {
|
50
|
if (!isset($list[$key]) || $list[$key] === false) {
|
51
|
return false;
|
52
|
}
|
53
|
}
|
54
|
return true;
|
55
|
}
|
56
|
|
57
|
|
58
|
|
59
|
$fields_spec = array('lat' => array('numeric'),
|
60
|
'lon' => array('numeric'),
|
61
|
'alt' => array('numeric', 'positive'),
|
62
|
'loop' => array('boolean'),
|
63
|
'titre' => array('required'),
|
64
|
);
|
65
|
|
66
|
$validator = new FormValidator($fields_spec);
|
67
|
|
68
|
|
69
|
|
70
|
$upload_success = false;
|
71
|
$uploaded_filepath = '';
|
72
|
|
73
|
if ($validator->validate($_REQUEST)) {
|
74
|
try {
|
75
|
$uploaded_filepath = handle_upload();
|
76
|
$upload_success = true;
|
77
|
$message = sprintf("transfert de %s réalisé", basename($uploaded_filepath));
|
78
|
} catch (UploadReceiveError $e) {
|
79
|
$message = $e->getMessage();
|
80
|
}
|
81
|
} else {
|
82
|
$message = 'paramètres invalides';
|
83
|
}
|
84
|
|
85
|
|
86
|
|
87
|
$params_success = false;
|
88
|
|
89
|
if ($upload_success) {
|
90
|
$vals = $validator->sane_values();
|
91
|
|
92
|
|
93
|
if (existant_and_set($vals, array('lat', 'alt', 'lon', 'titre'))) {
|
94
|
try {
|
95
|
$panorama = site_point::create($uploaded_filepath);
|
96
|
$panorama->set_param('titre', 'Sans nom 1');
|
97
|
$panorama->set_param('latitude', $vals['lat']);
|
98
|
$panorama->set_param('longitude', $vals['lon']);
|
99
|
$panorama->set_param('altitude', $vals['alt']);
|
100
|
$panorama->set_param('image_loop', $vals['loop']);
|
101
|
$panorama->set_param('titre', $vals['titre']);
|
102
|
$panorama->save_params();
|
103
|
$params_success = true;
|
104
|
} catch (Exception $e) {
|
105
|
$message = 'erreur à la création du panorama : '.$e->getMessage();
|
106
|
}
|
107
|
}
|
108
|
}
|
109
|
|
110
|
|
111
|
|
112
|
|
113
|
|
114
|
|
115
|
if ($upload_success) {
|
116
|
utils::relative_redirect(
|
117
|
$panorama->get_generate_url(basename($uploaded_filepath)));
|
118
|
}
|
119
|
?>
|
120
|
|
121
|
<!DOCTYPE html>
|
122
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
|
123
|
<head>
|
124
|
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
|
125
|
<title>Transfert de panoramique</title>
|
126
|
</head>
|
127
|
<body>
|
128
|
<?php
|
129
|
if (isset($message)) {
|
130
|
echo "<h2>$message</h2>\n";
|
131
|
if ($validator->errors()) {
|
132
|
foreach($validator->errors() as $key => $error) {
|
133
|
printf('<p>"%s" : %s</p>', $_REQUEST[$key], $error);
|
134
|
}
|
135
|
}
|
136
|
}
|
137
|
?>
|
138
|
</body>
|
139
|
</html>
|