
Problemas cargando csv a mysql
Publicado por David (38 intervenciones) el 04/10/2014 04:20:58
Buen dia, tengo un formulario en php para subir csv a unas tablas en mysql, cuando lo ejecuto por primera vez funciona perfectamente pero cuando deseo subir otro archivo de inmediato me arroja error. Les comparto el import.php
Formulario:
import.php
Creo que es el lio esta en echo $filename=$_FILES["file"]["tmp_name"]; pero no estoy seguro.
Muchas gracias por su colaboracion.
SAludos
Formulario:
1
2
3
<form action="import.php" method="post" name="upload_excel" enctype="multipart/form-data">
<input type="file" name="file" id="file">
<button type="submit" id="submit" name="Import"data-loading-text="Loading...">Subir</button>
import.php
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
<?php
include 'db.php';
if(isset($_POST["Import"])){
echo $filename=$_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"] > 0)
{
$file = fopen($filename, "r");
while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
{
//It wiil insert a row to our subject table from our csv file`
$sql = "INSERT into primero (id, temporada, area, proyecto, isbn, licencia)
values('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]','$emapData[5]')";
//we are using mysql_query function. it returns a resource on true else False on error
$result = mysql_query( $sql, $conn );
if(! $result )
{
echo "<script type=\"text/javascript\">
alert(\"Invalid File:Please Upload CSV File.\");
window.location = \"index.php\"
</script>";
}
}
fclose($file);
//throws a message if data successfully imported to mysql database from excel file
echo "<script type=\"text/javascript\">
alert(\"CSV File has been successfully Imported.\");
window.location = \"index.php\"
</script>";
//close of connection
mysql_close($conn);
}
}
?>
Creo que es el lio esta en echo $filename=$_FILES["file"]["tmp_name"]; pero no estoy seguro.
Muchas gracias por su colaboracion.
SAludos
Valora esta pregunta


0