problemas load data urgente!!!
Publicado por jota (2 intervenciones) el 08/06/2007 01:30:58
amigos, tengo un problema hace dias que no he podido solucionar. necesito, mediante un formulario, seleccionar un archivo del disco duro, el archivo es .csv. la idea es que al precionar en el boton "cargar", se cargen los datos del archivo de texto a una tabla que tengo el phpmyadmin del mi hosting. el archivo .csv esta separado por "," por ejemplo 1212121212,54600 el codigo es el siguiente;
cargamain.php
<form name = "carga" method="POST" action="cargaexit.php">
<td width="203" height="32"><div align="right"><span class="style1">Archivo csv : </span></div></td>
<td colspan="2"><input type="file" name="csvarchivo" size="32" /></td>
</tr>
<tr >
<td ><div align="right" ></div></td>
<td ><input type="submit" name="carga" value=" Cargar ">
</td>
</tr>
<tr >
<td colspan="3"><div align="right">
</div></td>
</form>
cargaexit.php
<?php
$connection = mysql_connect ("localhost", "xxxxxx", "xxxxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xxxxx", $connection);
$fp=fopen($_POST[csvarchivo],"r") or die("Erro al abrir el fichero");
$line = fgets( $fp, 2024 );
while(!feof($fp))
{
list($id,$saldo) =split( ";", $line);
$line = fgets( $fp, 2024 );
$db_query1 ="INSERT INTO xxxxx(xxxxx_id, xxxxx_actual) VALUES('$id','$saldo')";
$resul = mysql_query($db_query1);
}
fclose($fp);
?>
helpme plisssssssssss
gracias...
cargamain.php
<form name = "carga" method="POST" action="cargaexit.php">
<td width="203" height="32"><div align="right"><span class="style1">Archivo csv : </span></div></td>
<td colspan="2"><input type="file" name="csvarchivo" size="32" /></td>
</tr>
<tr >
<td ><div align="right" ></div></td>
<td ><input type="submit" name="carga" value=" Cargar ">
</td>
</tr>
<tr >
<td colspan="3"><div align="right">
</div></td>
</form>
cargaexit.php
<?php
$connection = mysql_connect ("localhost", "xxxxxx", "xxxxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xxxxx", $connection);
$fp=fopen($_POST[csvarchivo],"r") or die("Erro al abrir el fichero");
$line = fgets( $fp, 2024 );
while(!feof($fp))
{
list($id,$saldo) =split( ";", $line);
$line = fgets( $fp, 2024 );
$db_query1 ="INSERT INTO xxxxx(xxxxx_id, xxxxx_actual) VALUES('$id','$saldo')";
$resul = mysql_query($db_query1);
}
fclose($fp);
?>
helpme plisssssssssss
gracias...
Valora esta pregunta


0