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
|
<?php
if(!defined('IN_INDEX')){
exit();
}
$_SESSION['action']="module/administration/action.php";
/*switch($_POST['action']){
case "ajouter" :*/
if(isset($_POST['valideImport'])){
//On ouvre le fichier à importer en lecture seule
if (isset($_FILES['fichier']['tmp_name']) && is_uploaded_file($_FILES['fichier']['tmp_name'])) {
$fp = fopen($_FILES['fichier']['tmp_name'], "r");
}
while (!feof($fp)) //on importe le fichier
{
$ligne = fgets($fp,4096);//tant qu'on est pas à la fin du fichier, on li une ligne
$liste = explode( ";",$ligne); // On récupère les champs séparés par ; dans liste
//On assigne les variables
$login = $liste[0];
$password = $liste[1];
$nom = $liste[2];
$prenom = $liste[3];
$profil = $liste[4];
$rue = $liste[5];
$cp = $liste[6];
$ville = $liste[7];
$mail = $liste[8];
$tel_fixe = $liste[9];
$tel_portable = $liste[10];
//On ajoute un nouvelle enregistrement dans la table
$connexion->exec('INSERT INTO collaborateur (login,password,nom,prenom,profil,rue,cp,ville,mail,tel_fixe,tel_portable,site_id) VALUES ("'.$login.'","'.$password.'","'.$nom.'","'.$prenom.'","'.$profil.'","'.$rue.'","'.$cp.'","'.$ville.'","'.$mail.'","'.$tel_fixe.'","'.$tel_portable.'")');
}
echo "<br>Importation terminée, avec succès.";
//On ferme le fichier
fclose($fp);
}
//break;
//default:
?>
<?php echo "<form method=\"post\" action=\"$PHP_SELF\" enctype=\"multipart/form-data\">"; ?>
<br/>
Choisir le fichier ".csv" à importer :
<br/>
<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td>Fichier :</td>
<td>
<input type="hidden" name="MAX_FILE_SIZE"* value="4000" />
<input id="fichier" type="file" name="fichier" />
</td>
</tr>
<tr>
<td></td>
<td> <input type="submit" value="Importer" name="valideImport" > </td>
</tr>
</table>
<input type="hidden" name="action" value="ajouter">
</form>
<?php
//break;
//}
?> |
Partager