envoiFichiers.php 2.66 KB
<?php
session_start();
$error = false;

if ( isset($_POST['sensor']) && count($_POST['sensor']<>0) ) {
     	$xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\r\n"
	.'<all>';
     	foreach($_POST['sensor'] as $sensor => $value)
	{
		$val = explode(":", $value);
		if(count($types)<>0 && !in_array($val[2], $types)) {$error = true;}
		else {$types[] = $val[2];}
		$xml = $xml. '<sensor>' . '<raspberry>' . htmlspecialchars($val[0]) . '</raspberry>' . '<numero>' . htmlspecialchars($val[1]) . '</numero>' . '</sensor>';
		$xml = $xml."\r\n";
	}
	$xml = $xml.'</all>';
        if(!$error) {file_put_contents('upload/sensor.xml', $xml) ;}
}
?>
<!DOCTYPE html>

<html>
	<head>
		<?php include("head.php"); ?>
	</head>

	<!-- Contenu du site -->
	<body>
		<?php 
		include("header.php");
		if(!$error)
		{
		$upload1 = upload('fichier',FALSE, array('c', 'txt') );
		?>
		<div class="row">
			<div class="col-4 col-md-4 offset-md-4 offset-4">
				<br/>
				<h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fa fa-cloud"></i> Envoi du fichier en ligne</h1>
				<?php if($upload1){
					?>
					<div class="alert alert-success" role="alert">
					  Upload du fichier réussi !
					</div>
					<?php
				}
				else {?>
					<div class="alert alert-danger" role="alert">
						Erreur lors du transfert du fichier !
					</div><?php 
				}
				?>
				<h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fa fa-info-circle"></i> Informations complémentaires</h1>
				<table class="table table-striped table-bordered">
					<tbody>
						<tr>
							<td>Nom du fichier</td>
							<td><?php echo $_FILES['fichier']['name'];?></td>
						</tr>
						<tr>
							<td>Type</td>
							<td><?php echo $_FILES['fichier']['type'];?></td>
						</tr>
						<tr>
							<td>Localisation</td>
							<td><?php echo $_FILES['fichier']['tmp_name'];?></td>
						</tr>
						<tr>
							<td>Erreur</td>
							<td><?php echo $_FILES['fichier']['error'];?></td>
						</tr>
						<tr>
							<td>Taille</td>
							<td><?php echo $_FILES['fichier']['size'];?></td>

						</tr>
					</tbody>
				</table>

			</div>
		</div>
		<?php }
		else
		{
		?>
		<div class="row">
			<div class="col-4 col-md-4 offset-md-4 offset-4">
				<br/>
				<h1 style="margin-bottom:50px; margin-top:50px; border-bottom:1px solid #CCC; padding-bottom:20px;"><i class="fa fa-cloud"></i> Envoi du fichier en ligne</h1>
				<div class="alert alert-danger" role="alert">
				     Vous devez choisir des capteurs de même type !
				</div>
				<meta http-equiv="Refresh" content="3;url=send.php" />
			</div>
		</div>
		<?php
		}
		?>
	</body>
</html>