Php fopen()[function.fopen]错误
我正在开发一个系统,当我试图将.csv文件上传到数据库时,出现了这个错误 警告:fopen()[function.fopen]:第14行C:\xampp\htdocs\cubaan\importsv.php中的文件名不能为空 指的是我的编码Php fopen()[function.fopen]错误,php,file,Php,File,我正在开发一个系统,当我试图将.csv文件上传到数据库时,出现了这个错误 警告:fopen()[function.fopen]:第14行C:\xampp\htdocs\cubaan\importsv.php中的文件名不能为空 指的是我的编码 <html> <form name="import" method="post" enctype="multipart/form-data"> <b> Import your .csv (Excel) here</
<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");
}
}
?>
在此处导入.csv(Excel)
为了避免警告,您需要将if(isset($\u POST[“submit”])
更改为if(isset($\u FILES[“file”][“tmp\u name”])
你的表格看起来不错,上传对我来说也很好。确保在php.ini中启用了上载,并且启用了上载
file_uploads = On
文件名为空$\u FILES['file']['tmp\u name']
生成了一个空字符串,这意味着您上载的内容不是名为file
的文件<代码>$\u FILES['file.csv']['tmp_name']
可能?您的表单输入名称是什么?它仍然无法工作@grochmal,请查看我的更新编码@jeffpuckettii您是否选择并上传表单中的文件?确保您也检查了$\u文件['file']['error']