Révision ffa856dc
Ajouté par Jocelyn Delande il y a presque 11 ans
uploadReceive.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 | 3 |
require_once('class/FormValidator.class.php'); |
4 |
require_once('class/site_point.class.php'); |
|
4 | 5 |
require_once('constants.inc.php'); |
5 | 6 |
|
6 | 7 |
class UploadReceiveError extends Exception {} |
... | ... | |
23 | 24 |
if(!empty($file)) { |
24 | 25 |
if(isset($file) && UPLOAD_ERR_OK === $file_err) { |
25 | 26 |
move_uploaded_file($file_tmp, $file_finalpath); |
26 |
return sprintf("transfert de %s réalisé", $file);
|
|
27 |
return $file_finalpath;
|
|
27 | 28 |
} else { |
28 | 29 |
throw new UploadReceiveError( |
29 | 30 |
'Une erreur interne a empêché l\'envoi de l\'image :'. $file_err); |
... | ... | |
35 | 36 |
} |
36 | 37 |
} |
37 | 38 |
|
39 |
function existant_and_set($list, $keys) { |
|
40 |
/** For HTTP data : keys of $keys are set within $list and they are not empty |
|
41 |
* or false nor empty |
|
42 |
*/ |
|
43 |
foreach($keys as $key) { |
|
44 |
if (!isset($list[$key]) || !$list[$key]) { |
|
45 |
return false; |
|
46 |
} |
|
47 |
} |
|
48 |
return true; |
|
49 |
} |
|
50 |
|
|
38 | 51 |
////////////////////// main ////////////////////////////////////////// |
39 | 52 |
|
40 |
$fields_spec = array('lat' => array('required', 'numeric', 'positive'),
|
|
53 |
$fields_spec = array('lat' => array('numeric', 'positive'), |
|
41 | 54 |
'lon' => array('numeric', 'positive'), |
42 |
'alt' => array('numeric'), |
|
55 |
'alt' => array('numeric', 'positive'), |
|
56 |
'loop' => array('boolean'), |
|
43 | 57 |
); |
44 | 58 |
|
45 | 59 |
$validator = new FormValidator($fields_spec); |
46 |
$upload_success = false; |
|
47 | 60 |
|
48 | 61 |
////// STEP 1 : UPLOAD //////// |
49 | 62 |
|
63 |
$upload_success = false; |
|
64 |
$uploaded_filepath = ''; |
|
65 |
|
|
50 | 66 |
if ($validator->validate($_REQUEST)) { |
51 | 67 |
try { |
52 |
$message = handle_upload();
|
|
68 |
$uploaded_filepath = handle_upload();
|
|
53 | 69 |
$upload_success = true; |
70 |
$message = sprintf("transfert de %s réalisé", basename($uploaded_filepath)); |
|
54 | 71 |
} catch (UploadReceiveError $e) { |
55 | 72 |
$message = $e->getMessage(); |
56 | 73 |
} |
... | ... | |
63 | 80 |
$params_success = false; |
64 | 81 |
|
65 | 82 |
if ($upload_success) { |
66 |
//pass |
|
83 |
$vals = $validator->sane_values(); |
|
84 |
// There is no point setting a part of the parameters only ; check that all |
|
85 |
// are present. |
|
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');//FIXME |
|
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 |
} |
|
67 | 100 |
} |
68 | 101 |
|
69 | 102 |
|
Formats disponibles : Unified diff
added params generation to upload