| 12
 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
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 
 | <FORM ENCTYPE="multipart/form-data" ACTION="imp_facture.php" METHOD="POST">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000">
Envoyez ce fichier : <INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Send File">
</FORM>
 
<table width="800" border="1" align="center" cellpadding="2" cellspacing="0" bgcolor="#eeeeee">
<tr>
  <td>id_numero</td>
  <td>facture</td>
  <td>intitule</td>
  <td>montant </td>
  <td>session</td>
  <td>date_fact</td>
  <td>date_echeance</td>
  <td>relance</td>
  <td>l_01</td>
  <td>l_02</td>
  <td>l_03</td>
  <td>annee</td>  
 
</tr>
 
<?php
 
require_once('../config/connexion.php');
 
if( isset( $_POST['userfile']) ) 
{ 
//=========================
// 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
?>
<p align="center" >- Importation échouée -</p>
<p align="center" ><B>Désolé, mais vous n'avez pas spécifié de chemin valide ...</B></p>
<?php
exit();
}
// declaration de la variable "cpt" qui permettra de compter le nombre d'enregistrement réalisé
$cpt=0;
?>
<p align="center">- Importation Réussie -</p>
 
<p align="right"><a href="#bas">Bas de page</a></p>
 
<?php
// 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[1] = ( isset($liste[1]) ) ? $liste[1] : Null;
$liste[2] = ( isset($liste[2]) ) ? $liste[2] : Null;
$liste[3] = ( isset($liste[3]) ) ? $liste[3] : Null;
$liste[5] = ( 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;
$liste[11] = ( isset($liste[11]) ) ? $liste[11] : Null;
$liste[12] = ( isset($liste[12]) ) ? $liste[12] : Null;
 
 
$champs1=$liste[1]; // id_numero
$champs2=$liste[2]; // facture
$champs3=$liste[3]; // intitule
$champs4=$liste[4]; // montant
$champs5=$liste[5]; // date_fact
$champs6=$liste[6]; // date_echeance
$champs6=$liste[7]; // relance
$champs6=$liste[8]; // l_01
$champs6=$liste[9]; // l_02
$champs6=$liste[10]; // l_03
$champs6=$liste[11]; // l_04
$champs6=$liste[12]; // annee
 
 
// pour eviter qu un champs "nom" du fichier soit vide
if ($champs1!='')
{
// nouvel ajout, compteur incrémenté
$cpt++;
// requete et insertion ligne par ligne
 
$sql= "INSERT INTO facture (id_numero,facture,intitule,montant,date_fact,date_echeance,relance,l_01,l_02,l_03,l_04,annee)
		VALUES('$champs1','$champs2','$champs3','$champs4','$champs5','$champs6','$champs7','$champs8','$champs9','$champs10','$champs11','$champs12') ";
 
  //exécution de la requête SQL:
  $requete = mysql_query($sql, $cnx) or die( mysql_error() ) ;
  }
  else 
  {
	echo 'Merci de reposter le fichier';
  }
 
?>
<tr>
<td width="124">Eléments importés :</td>
<td width="60"><?php echo $champs1;?></td>
<td width="70"><?php echo $champs2;?></td>
<td width="500"><?php echo $champs3;?></td>
<td width="60"><?php echo $champs4;?></td>
<td width="60"><?php echo $champs5;?></td>
<td width="60"><?php echo $champs6;?></td>
<td width="60"><?php echo $champs7;?></td>
<td width="60"><?php echo $champs8;?></td>
<td width="60"><?php echo $champs9;?></td>
<td width="60"><?php echo $champs10;?></td>
<td width="60"><?php echo $champs11;?></td>
<td width="10"><?php echo $champs12;?></td>
</tr>
 
<?php
}
}
 
// fermeture du fichier
fclose($fp);
//on supprime la derniere car elle est vide
 
 
//==================
// FIN
//==================
?>
</table>
<br><br>Nombre de valeurs nouvellement enregistrées: <b><?php echo $cpt;?></b> | 
Partager