je suis entrain d'ecrire un script php pour importer des données dans une table et voila le script obtenu a la fin
<?php
try
{
$pdo = new PDO('mysql:host=localhost;dbname=projetemedia;charset=utf8', 'root', '');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
//UPLOAD DU FICHIER CSV, vérification et insertion en BASE
if(isset($_FILES["file"]["type"]) != "application/vnd.ms-excel"){
die("Ce n'est pas un fichier de type .csv");
}
elseif(is_uploaded_file($_FILES['file']['tmp_name'])) {
//$row = 1;
if (($handle = fopen($_FILES['file']['tmp_name'], "r")) !== FALSE) {
fgetcsv($handle);
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
$col[$c] = $data[$c];
}
$col1 = $col[0];
$col2 = $col[1];
$col3 = $col[2];
$col4 = $col[3];
$col5 = $col[4];
$col6 = $col[5];
$col7 = $col[6];
$col8 = $col[7];
$col9 = $col[8];
$col10 = $col[9];
$col11 = $col[10];
$req = $pdo->prepare('INSERT INTO entreprise (id, RaisonSociale, Activite, pays, ville, Email, Telephone, Gerant,
AutreContact, TelephoneDirecteur, EmailDirecteur, Fonction) VALUES(?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$req->execute(array('',$col1, $col2, $col3,$col4, $col5, $col6, $col7,$col8, $col9, $col10, $col11));
}
fclose($handle);
}
}
?>. Mais je n'obtiens pas le resultat souhaiter.voici mon code pour importer le fichier
<form enctype="multipart/form-data" action="import.php" method="POST">
<div class="form-group">
<input name="file" type="file" />
<p><input type="submit" value="Envoyez le fichier" /></p>
</div>
</form>