Bon finalement j'ai essayé avec le \n ça marche. Avec ma méthode, ça ajoutait un \n dans le premier champs de la table (un peu gênant).
Maintenant je me retrouve avec 2 problèmes (un assez simple j'imagine mais l'autre...)
1) Les caractères spéciaux sont envoyés en tant que '?' dans la BDD. Pourtant j'ai mis en début de page:
mysql_query("SET NAMES UTF8");
2) Il n'enregistre pas tout. Il bloque vers le milieu et m'affiche:
Notice: Undefined offset: 1 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 3 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 8 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 9 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 11 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 4 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 12 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 14 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 15 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 1 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 3 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 8 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 9 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 11 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 4 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 12 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 14 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
Notice: Undefined offset: 15 in C:\Documents and Settings\Administrateur\Bureau\EasyPHP-5.3.6.0\local\www\abscence\upload.php on line 26
INSERT INTO etudiant(nom,prenom,numetu,adresse,adresse2,cp,sexe,ville,version,etape) VALUES('','','','','','','','','','') ON DUPLICATE KEY UPDATE nom = '',prenom = '',numetu = '',adresse = '',adresse2 = '',cp = '',sexe = '',ville = '',version = '',etape = ''
Tout ça 2 fois de suite. J'avoue que sur ce coup la je sèche un peu.
Voici le code au complet:
<?php
include 'fonctions.php';
conect_db();
session_start();
mysql_query("SET NAMES UTF8");
if(!isset($_SESSION['login'])) header("Location: index.php");
if (isset($_FILES['fichier'])) {
$txt = $_FILES['fichier']['name'];
$chemin_destination = 'upload\\';
move_uploaded_file($_FILES['fichier']['tmp_name'], $chemin_destination.$_FILES['fichier']['name']);
$handle = fopen("upload\\".$txt."", "rb");
$contents = stream_get_contents($handle);
$contents = str_replace("'","\'",$contents);
$ligne = explode("\n", $contents);
//$ligne = nl2br($ligne);
//$ligne = explode("<br />", $ligne);
for($i=0;$i < sizeof($ligne);$i++)
{
$champs = explode(";", $ligne[$i]);
$sql = "INSERT INTO etudiant(nom,prenom,numetu,adresse,adresse2,cp,sexe,ville,version,etape) VALUES('".$champs[1]."','".$champs[3]."','".$champs[0]."','".$champs[8]."','".$champs[9]."','".$champs[11]."','".$champs[4]."','".$champs[12]."','".$champs[14]."','".$champs[15]."') ON DUPLICATE KEY UPDATE nom = '".$champs[1]."',prenom = '".$champs[3]."',numetu = '".$champs[0]."',adresse = '".$champs[8]."',adresse2 = '".$champs[9]."',cp = '".$champs[11]."',sexe = '".$champs[4]."',ville = '".$champs[12]."',version = '".$champs[14]."',etape = '".$champs[15]."'";
echo $i.' '.$sql.'<br><br>';
mysql_query($sql) or die (mysql_error());
}
fclose($handle);
}
include 'header.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Abscences - accueil</title>
</head>
<body>
<div class="contenu">
<form method="post" enctype="multipart/form-data" action="#">
<fieldset>
<p>
<input type="file" name="fichier" size="30">
<input type="submit" name="upload" value="Uploader">
</p>
</fieldset>
</form>
</div>
</body>
</html>