1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
   |  
<div id='contenu'>
	<br><br>
 
	<form method="post" enctype="multipart/form-data">
		<table width="628" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#eeeeee">
			<tr>
				<td width="500"><font size=3><b>Selectionner votre fichier *.csv :</b></font></td>
				<td width="244" align="center"><input type="file" name="userfile" value="userfile"></td>
				<td width="137" align="center"><input type="submit" value="Envoyer" name="envoyer"></td>
			</tr>
		</table>
	</form>
 
<!--récupération en php-->
 
<?php
if(isset($_POST['envoyer']))
{
 
	require_once('connect.php');
 
	//=========================
	// Traitement des donnees
	//=========================
 
	//recupere le nom du fichier indiqué par l'user
	$fichier=$_FILES["userfile"]["name"];
 
	// ouverture du fichier en lecture
	if ($fichier)
	{
	//ouverture du fichier temporaire
		$fp = fopen ($_FILES["userfile"]["tmp_name"], "r");
	}
	else
	{
	// fichier inconnu
		echo '<p align="center" >- Importation échouée -</p>';
		echo '<p align="center" ><B>Désolé, mais vous n\'avez pas spécifié de chemin valide ...</B></p>';
		exit();
	}
 
	// declaration de la variable "cpt" qui permettra de compter le nombre d'enregistrement réalisé
	$cpt=0;
	echo '<p align="center">- Importation Réussie -</p>';
 
	// importation
	while (!feof($fp))
	{
		$ligne = fgets($fp,4096);
	// on crée un tableau des élements séparés par des points virgule
		$liste = explode(";",$ligne);
	// premier élément
		$liste[0] = ( isset($liste[0]) ) ? $liste[0] : Null;
		$liste[1] = ( isset($liste[1]) ) ? $liste[1] : Null;
		$liste[2] = ( isset($liste[2]) ) ? $liste[2] : Null;
		$liste[3] = ( isset($liste[3]) ) ? $liste[3] : Null;
		$liste[4] = ( isset($liste[4]) ) ? $liste[4] : Null;
		$liste[5] = ( isset($liste[5]) ) ? $liste[5] : Null;
		$liste[6] = ( isset($liste[6]) ) ? $liste[6] : Null;
		$liste[7] = ( isset($liste[7]) ) ? $liste[7] : Null;
		$liste[8] = ( isset($liste[8]) ) ? $liste[8] : Null;
		$liste[9] = ( isset($liste[9]) ) ? $liste[9] : Null;
		$liste[10] = ( isset($liste[10]) ) ? $liste[10] : Null;
 
		$champs1=$liste[0];
		$champs2=$liste[1];
		$champs3=$liste[2];
		$champs4=$liste[3];
		$champs5=$liste[4];
		$champs6=$liste[5];
		$champs7=$liste[6];
		$champs8=$liste[7];
		$champs9=$liste[8];
		$champs10=$liste[9];
		$champs11=$liste[10];
 
		if ($champs1!='')
		{
		// nouvel ajout, compteur incrémenté
		$cpt++;
		// requete et insertion ligne par ligne
		// champs1 id en general dc on affecte pas de valeur
 
		mysql_query("INSERT INTO ordredefabrication(DateDuJour, DateDebutFab, Ref, Essences, Clients, Chantiers, SemaineFinFab, Types, Temps, NomPoseurs, Dep, Ville) VALUES(CURRENT_DATE,'$champs1','$champs2','$champs3','$champs4','$champs5','$champs6','$champs7','$champs8','$champs9','$champs10','$champs11' )");
 
		echo '<table width="800" border="1" align="center" cellpadding="0" cellspacing="0" bgcolor="#eeeeee">
			<tr>
				<td width="124">Eléments importés :</td>';
				echo '<td width="361">'.$liste[0].'</td>';
				echo '<td width="361">'.$liste[1].'</td>';
				echo '<td width="361">'.$liste[2].'</td>';
				echo '<td width="361">'.$liste[3].'</td>';
				echo '<td width="361">'.$liste[4].'</td>';
				echo '<td width="361">'.$liste[5].'</td>';
				echo '<td width="361">'.$liste[6].'</td>';
				echo '<td width="361">'.$liste[7].'</td>';
				echo '<td width="361">'.$liste[8].'</td>';
				echo '<td width="361">'.$liste[9].'</td>';
				echo '<td width="361">'.$liste[10].'</td>
			</tr>
		</table>';
		}
	}
 
	// fermeture du fichier
	fclose($fp);
	//on supprime la derniere car elle est vide
 
 
	//==================
	//
 
echo '<br><br>Nombre de valeurs nouvellement enregistrées: <b>'.$cpt.'</b>.<br><br>';	
}
 
?>
</div> | 
Partager