我正在开发一个系统,当我试图将.csv文件上传到数据库时,遇到了这个错误。
警告: fopen() function.fopen:文件名不能在第14行的C:\xampp\htdocs\cubaan\importcsv.php中为空
指的是我的编码,
<html>
<form name="import" method="post" enctype="multipart/form-data">
<b> Import your .csv (Excel) here</b><br/><br/>
<input type="file" name="file"/><br />
<input type="submit" name="submit" value="Submit" /><br/>
</form>
<?php
include ("connection.php");
if(isset($_POST["submit"]))
{
$file = $_FILES['file']['tmp_name'];<--line 14
$handle = fopen($file, "r");
$c = 0;
$row = 1;
while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
{
if($row == 1)
{
$row++; continue;
}
$num = count($filesop);
$id = $filesop[0];
$name = $filesop[1];
$address = $filesop[2];
$contact1 = $filesop[3];
$contact2 = $filesop[4];
$department = $filesop[5];
$lokasi = $filesop[6];
$sql = mysql_query("INSERT INTO customer_details (id,customer_name,customer_address,customer_contact1,customer_contact2,department,lokasi) VALUES ($id,'$name','$address','$contact1','$contact2','$department','$lokasi')");
$c = $c + 1;
}
if($sql){
echo "You database has imported successfully. You have inserted ". $c ." records";
}else{
echo "Sorry! There is some problem.";
}
include ("ex.php");
if(isset($_POST["submit"]))
{
ExportExcel("customer_details");
}
}
?>文件中包含的数据不会上载到数据库中。我在另一个问题上寻找了同样的错误,但没有起作用。我上传的数据

发布于 2016-06-08 02:43:33
为了避免警告,您需要将if(isset($_POST["submit"]))更改为if(isset($_FILES['file']['tmp_name']))
你的表格看起来不错,上传对我也很好。确保您有enabled error reporting,并且在您的php.ini中启用了上载
file_uploads = Onhttps://stackoverflow.com/questions/37692009
复制相似问题