到目前为止,我的代码段:
if(isset($_POST['submit'])) {
$uploaddir = '/www/csvExtraction/uploads/';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
}
还是我得到这个错误
Undefined index: file in C:\wamp\www\csvExtraction\index.php
完整代码:
if(!$db)
die("no db");
if(!mysqli_select_db($db,"phptester"))
die("No database selected.");
if(isset($_POST['submit']))
{
$uploaddir = '/www/csvExtraction/uploads/';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
{
$handle = fopen("$uploadfile", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$import="INSERT into sample(id,name,address) values('$data[0]','$data[1]','$data[2]')";
mysqli_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";
}
}
else
{
print "
";print "Choose file to import:
";
print "
";
//print "
";
print "
";}
?>
解决方法:
我有解决办法.
$db = mysqli_connect("localhost", "root", "") or die("could not connect");
if(!$db)
die("no db");
if(!mysqli_select_db($db,"phptester"))
die("No database selected.");
if(isset($_POST['submit']))
{
$uploaddir = 'uploads/';
$uploadfile = $uploaddir . basename($_FILES["file"]["name"]);
echo $uploadfile;
if (move_uploaded_file($_FILES["file"]["tmp_name"], $uploadfile))
{
$handle = fopen("$uploadfile", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$import="INSERT into sample(id,name,address) values('$data[0]','$data[1]','$data[2]')";
mysqli_query($db,$import) or die(mysql_error());
}
fclose($handle);
print "Import done";
}
}
else
{
print "
";print "Choose file to import:
";
print "
";
print "
";}
?>
标签:html,php
来源: https://codeday.me/bug/20191028/1954014.html