Commit 705b4085bd2b19f17f86c33c30a8f961ecff41b3
1 parent
bc7fc652
MAJ Site
Showing
5 changed files
with
150 additions
and
18 deletions
Show diff stats
site/accesBase.php
... | ... | @@ -81,11 +81,6 @@ |
81 | 81 | |
82 | 82 | function upload($index,$maxsize=FALSE,$extensions=FALSE) |
83 | 83 | { |
84 | - //Creation du dossier | |
85 | - /*$dossier = "upload"; | |
86 | - if(!is_dir($dossier)) | |
87 | - if(!mkdir($dossier, 0777)) | |
88 | - echo "Impossible de creer le dossier";*/ | |
89 | 84 | //Test1: fichier correctement uploadé |
90 | 85 | if (!isset($_FILES[$index]) OR $_FILES[$index]['error'] > 0) return FALSE; |
91 | 86 | //Test2: taille limite |
... | ... | @@ -93,7 +88,7 @@ |
93 | 88 | //Test3: extension |
94 | 89 | $ext = substr(strrchr($_FILES[$index]['name'],'.'),1); |
95 | 90 | if ($extensions !== FALSE AND !in_array($ext,$extensions)) return FALSE; |
96 | - $name = 'binaire'; | |
91 | + $name = "binaire"; | |
97 | 92 | $extension_upload = strtolower( substr( strrchr($_FILES['fichier']['name'], '.') ,1) ); |
98 | 93 | $dossier = "upload/"; |
99 | 94 | $fichier = $name.".".$extension_upload; |
... | ... | @@ -101,6 +96,21 @@ |
101 | 96 | return move_uploaded_file($_FILES['fichier']['tmp_name'],$dossier.$fichier); |
102 | 97 | } |
103 | 98 | |
99 | + function load($tmp_name, $name) | |
100 | + { | |
101 | + $dossier = "upload/"; | |
102 | + $fichier = "main.c"; | |
103 | + $taille_max = 100000; | |
104 | + $taille = filesize($tmp_name); | |
105 | + $extensions = Array('.c'); | |
106 | + $extension = strrchr($name, '.'); | |
107 | + if(in_array($extension, $extensions) && taille <= taille_max) | |
108 | + { | |
109 | + return move_uploaded_file($tmp_name, $dossier.$fichier); | |
110 | + } | |
111 | + return False; | |
112 | + } | |
113 | + | |
104 | 114 | function update_values() |
105 | 115 | { |
106 | 116 | $rep = 'data'; |
... | ... | @@ -187,14 +197,14 @@ |
187 | 197 | return $tab['nom']; |
188 | 198 | } |
189 | 199 | |
190 | - function getSensorVersion($rasberry, $numero) | |
200 | + function getSensorVersion($raspberry, $numero) | |
191 | 201 | { |
192 | 202 | $db = connexion(); |
193 | 203 | $query = "SELECT version FROM capteurs where raspberry = '$raspberry' AND numero = $numero"; |
194 | 204 | $result = pg_query($db, $query) or die("La requète a echoué : ".pg_last_error()); |
195 | 205 | $tab = pg_fetch_assoc($result); |
196 | 206 | deconnexion($db); |
197 | - return $tab['version']; | |
207 | + return (int)$tab['version']; | |
198 | 208 | } |
199 | 209 | |
200 | 210 | function add($nom, $type, $raspberry, $numero, $unite) |
... | ... | @@ -216,5 +226,5 @@ |
216 | 226 | return False; |
217 | 227 | } |
218 | 228 | } |
219 | - } | |
229 | + } | |
220 | 230 | ?> | ... | ... |
site/capteurs.php
... | ... | @@ -5,8 +5,8 @@ $sensors = getSensors(); |
5 | 5 | <div class="row"> |
6 | 6 | <div class="col-6 col-md-6 offset-md-3 offset-3"> |
7 | 7 | <br/> |
8 | - <h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fa fa-bars"></i> Choix du capteur</h1> | |
9 | - <form action="envoiFichiers.php" method="post" enctype="multipart/form-data"> | |
8 | + <h1 style="margin-bottom:20px; margin-top:30px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fa fa-bars"></i> Choix du capteur</h1> | |
9 | + <form action="reception.php" method="post" enctype="multipart/form-data"> | |
10 | 10 | <table class="table table-striped table-bordered"> |
11 | 11 | <tbody> |
12 | 12 | <tr> |
... | ... | @@ -34,17 +34,17 @@ $sensors = getSensors(); |
34 | 34 | </tbody> |
35 | 35 | </table> |
36 | 36 | |
37 | - <h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fa fa-file-upload"></i> Uploader un fichier</h1> | |
38 | - <div class="panel panel-default"> | |
37 | + <h1 style="margin-bottom:20px; margin-top:30px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fa fa-file-upload"></i> Uploader un fichier</h1> | |
38 | + <div class="panel panel-default"> | |
39 | 39 | |
40 | 40 | <div class="form-group"> |
41 | - <label for="exampleFormControlFile1">Charger un fichier</label> | |
42 | - <input type="file" name="fichier" class="form-control-file" id="fichier"> | |
43 | - <input type="hidden" name="MAX_FILE_SIZE" value="1048576" /> | |
41 | + <label for="fichier">Charger un fichier</label> | |
42 | + <input type="file" name="fichier" class="form-control-file" id="fichier"> | |
44 | 43 | </div> |
45 | 44 | |
46 | 45 | </div> |
47 | - <input type="submit" class="btn btn-dark btn-lg btn-block"style="margin-top:50px;" value="Envoyer"/> | |
46 | + <input type="submit" class="btn btn-dark btn-lg btn-block"style="margin-top:20px;" value="Envoyer"/> | |
47 | + <br/> | |
48 | 48 | </form> |
49 | 49 | </div> |
50 | -</div> | |
51 | 50 | \ No newline at end of file |
51 | +</div> | ... | ... |
... | ... | @@ -0,0 +1,84 @@ |
1 | +<?php | |
2 | +session_start(); | |
3 | +require("accesBase.php"); | |
4 | +$err = false; | |
5 | + | |
6 | +if(isset($_POST['sensor'])) | |
7 | +{ | |
8 | + $ini = ""; | |
9 | + $arduino_simple = "[Arduino]\r\n"; | |
10 | + $arduino_spi = "[Arduino_spi]\r\n"; | |
11 | + $nucleo = "[Nucleo]\r\n"; | |
12 | + | |
13 | + $a_simple = false; | |
14 | + $a_spi = false; | |
15 | + $n = false; | |
16 | + | |
17 | + foreach($_POST['sensor'] as $sensor => $value) | |
18 | + { | |
19 | + $version = -1; | |
20 | + $val = explode(":", $value); | |
21 | + | |
22 | + if(count($types)<>0 && !in_array($val[2], $types)) {$err = true;} | |
23 | + else {$types[] = $val[2];} | |
24 | + | |
25 | + $version = getSensorVersion($val[0], $val[1]); | |
26 | + if($version == 0) | |
27 | + { | |
28 | + $a_simple = true; | |
29 | + $arduino_simple = $arduino_simple.$val[0]." capteur=".$val[1]."\n"; | |
30 | + } | |
31 | + elseif($version == 1) | |
32 | + { | |
33 | + $a_spi = true; | |
34 | + $arduino_spi = $arduino_spi.$val[0]." capteur=".$val[1]."\n"; | |
35 | + } | |
36 | + elseif($version == 2) | |
37 | + { | |
38 | + $n = true; | |
39 | + $nucleo = $nucleo.$val[0]." capteur=".$val[1]."\n"; | |
40 | + } | |
41 | + } | |
42 | + | |
43 | + if($a_simple) {$ini = $ini.$arduino_simple."\n";} | |
44 | + if($a_spi) {$ini = $ini.$arduino_spi."\n";} | |
45 | + if($n) {$ini = $ini.$nucleo."\n";} | |
46 | + | |
47 | + if(!$err) | |
48 | + { | |
49 | + file_put_contents('upload/inventaire.ini', $ini); | |
50 | + $upload = load($_FILES['fichier']['tmp_name'], $_FILES['fichier']['name']); | |
51 | + if($upload) | |
52 | + { | |
53 | + $message = "Upload du fichier réussi !"; | |
54 | + $color = "alert-success"; | |
55 | + } | |
56 | + else | |
57 | + { | |
58 | + $message = "Erreur lors du transfert du fichier..."; | |
59 | + $color = "alert-danger"; | |
60 | + } | |
61 | + } | |
62 | + else | |
63 | + { | |
64 | + $message = "Veuillez choisir des capteurs de même type !"; | |
65 | + $color = "alert-danger"; | |
66 | + } | |
67 | +} | |
68 | +?> | |
69 | + | |
70 | +<!DOCTYPE html> | |
71 | + | |
72 | +<html> | |
73 | + <head> | |
74 | + <?php include("head.php"); ?> | |
75 | + </head> | |
76 | + | |
77 | + <body> | |
78 | + <?php | |
79 | + include("header.php"); | |
80 | + include("reponse.php"); | |
81 | + if(!$err) {include("tableau.php");} | |
82 | + ?> | |
83 | + </body> | |
84 | +</html> | ... | ... |
... | ... | @@ -0,0 +1,30 @@ |
1 | +<div class="row"> | |
2 | + <div class="col-4 col-md-4 offset-4 offset-md-4"> | |
3 | + <h1 style="margin-bottom:20px; margin-top:30px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fa fa-info-circle"></i> Informations complémentaires</h1> | |
4 | + <table class="table table-striped table-bordered"> | |
5 | + <tbody> | |
6 | + <tr> | |
7 | + <td>Nom du fichier</td> | |
8 | + <td><?php echo $_FILES['fichier']['name'];?></td> | |
9 | + </tr> | |
10 | + <tr> | |
11 | + <td>Type</td> | |
12 | + <td><?php echo $_FILES['fichier']['type'];?></td> | |
13 | + </tr> | |
14 | + <tr> | |
15 | + <td>Localisation</td> | |
16 | + <td><?php echo $_FILES['fichier']['tmp_name'];?></td> | |
17 | + </tr> | |
18 | + <tr> | |
19 | + <td>Erreur</td> | |
20 | + <td><?php echo $_FILES['fichier']['error'];?></td> | |
21 | + </tr> | |
22 | + <tr> | |
23 | + <td>Taille</td> | |
24 | + <td><?php echo $_FILES['fichier']['size'];?></td> | |
25 | + </tr> | |
26 | + </tbody> | |
27 | + </table> | |
28 | + </div> | |
29 | +</div> | |
30 | + | ... | ... |