AJ93 AJ93 - 7 months ago 39
PHP Question

fopen() [function.fopen] error

I am developing a system and I got this error when I tried to upload .csv file into database.

Warning: fopen() [function.fopen]: Filename cannot be empty in C:\xampp\htdocs\cubaan\importcsv.php on line 14

which refer to my coding,


<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/>
include ("connection.php");

$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;

echo "You database has imported successfully. You have inserted ". $c ." records";
echo "Sorry! There is some problem.";
include ("ex.php");




the data contain inside the file is not uploaded into the database. I have look for the same error in the other question but nothing working.
The data that I upload


in order to avoid the warning, you need to change if(isset($_POST["submit"])) to if(isset($_FILES['file']['tmp_name']))

your form looks OK and the uploads work for me just fine. make sure you have enabled error reporting and that you have uploads enabled in your php.ini

file_uploads = On