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
| <html>
<head>
<style type="text/css">
<!--
.Style1 {
color: #80FFFF;
font-style: italic;
}
.Style2 {color: #000000}
-->
</style>
</head>
<body background="fond.jpg">
<?php
if (isset($_FILES['file']))
{
$file = $_FILES['file']['tmp_name'];
$handle = fopen($file,'r');
$row = 1;
$handle = fopen("$file", "r");
include("config.inc.php");
mysql_connect("$serveur_bdd", "$login_bdd", "$pass_bdd") or die('Erreur de connection à la base de données');
mysql_select_db("$table_bdd") or die('Erreur de connection à la table');
$req="TRUNCATE TABLE `user`";
mysql_query($req);
while (($data = fgetcsv($handle, 4096, ";")) !== FALSE)
{
$n = count($data);
$row++;
for($i=0;$i<$n;$i=$i+7)
{
$id="'".$data[$i]."'";
$nom="'".$data[$i+1]."'";
$prenom="'".$data[$i+2]."'";
$date_naiss ="'".$data[$i+3]."'";
$tel="'".addslashes($data[$i+4])."'";
$etablisse ="'".addslashes($data[$i+5])."'";
$niveau ="'".addslashes($data[$i+6])."'";
}
$reqinsert="INSERT INTO user VALUES(".$id.",".$nom.",".$prenom.",".$date_naiss.",".$tel.",".$etablisse.",".$niveau.");";
// execution de requette insertion
mysql_query($reqinsert);
echo $reqinsert;
echo '<br>';
}
mysql_close();
fclose($handle);
}
else
{
?><form action="upload.php" method="post" enctype="multipart/form-data" name="form1">
<pre class="Style1 Style2" > </pre>
<h1 ><center>Chargement des données :</h1>
<hr width="25%" size="4" color="black">
<br><br>
<hr width="35%" size="2">
<br>
Fichier : <input type="file" name="file">
<input type="submit" name="Submit" value="valider">
</form>
<?php
}
?>
<br><br>
<hr width="35%" size="2">
</body></html> |
Partager