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