steamngn
06-09-2007, 07:46 PM
Me again!:p
I have this code to import a csv file into mysql:
<?php
include "includes/stconfig.php";
if(isset($_POST['submit']))
{
$filename=$_POST['filename'];
$handle = fopen("$filename", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$import="INSERT into table1(test1,test2,test3) values('$data[0]','$data[1]','$data[2]')";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";
}
else
{
print "<form action='csv_importer.php' method='post'>";
print "Type file name to import:<br>";
print "<input type='file' name='filename' size='20'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>
What I need is to be able to select a LOCAL file, have it uploaded to a temp directory and imported into mysql, all from a web page. I don't dare turn this loose with myadmin, as the users will be nubes of the most extreme!
Anyway, is there a simple way to get what I have working?
Andy
I have this code to import a csv file into mysql:
<?php
include "includes/stconfig.php";
if(isset($_POST['submit']))
{
$filename=$_POST['filename'];
$handle = fopen("$filename", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$import="INSERT into table1(test1,test2,test3) values('$data[0]','$data[1]','$data[2]')";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";
}
else
{
print "<form action='csv_importer.php' method='post'>";
print "Type file name to import:<br>";
print "<input type='file' name='filename' size='20'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>
What I need is to be able to select a LOCAL file, have it uploaded to a temp directory and imported into mysql, all from a web page. I don't dare turn this loose with myadmin, as the users will be nubes of the most extreme!
Anyway, is there a simple way to get what I have working?
Andy