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
|
$fichier = $_FILES['fichier']['tmp_name'];
$row = 1;
if (($handle = fopen($fichier, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, "\r\n")) !== FALSE) {
$num = count($data);
$row++;
for ($c=1; $c < $num; $c++) {
//explode
$pieces = explode(";", $data[$c]);
$titre_question = htmlspecialchars(utf8_encode($pieces[0]));
$categorie = htmlspecialchars(utf8_encode($pieces[1]));
$categorie2 = htmlspecialchars(utf8_encode($pieces[2]));
if($titre_question != ''){
$sql = "INSERT INTO a_question(titre_question, categorie, categorie2) VALUES(\"$titre_question\", \"$categorie\", \"$categorie2\")";
$question = $bdd->query($sql);
$id_question = $bdd->lastInsertId();
}
$i = 3;
while($i < 13)
{
$reponse= htmlspecialchars(utf8_encode($pieces[$i]));
$ponderation = $pieces[$i + 1];
$remarque = htmlspecialchars(utf8_encode($pieces[$i + 2]));
echo "<br/>$reponse";
if($reponse != ''){
$rep = "INSERT INTO a_reponse(txt_reponse, id_question, ponderation,remarque) VALUES(\"$reponse\", \"$id_question\", \"$ponderation\", \"$remarque\")";
$reppp = $bdd->query($rep);
}
$i = $i +3;
}
}
}
fclose($handle);
} |