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