/beginnote This question was marked as 'duplicate'. It is different from the referenced question because in my application I cannot use LOAD IN as the input file will never be nicely formatted so I -have- to read it in line by line to test for valid records.
Also: in my working code I have changed from mysql_ to mysqli and I'm getting the same symptoms.
Also: I was told by my host provider that the browser errors I'm getting (500 or content encoding error) won't show up in the server log.
I'd like to re-open this and learn how to troubleshoot the problem. /endnote
I'm getting an error trying to insert records into MySQL from a CSV file in Firefox and Chrome. The CSV file has 300,000 lines. It will either be 'The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.' or just an Error 500.
Is the problem that the buffer is getting filled up? I tried using ob_clean() and flush() but that did not work. Ideas?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Process uploaded CSV file for Seatac Noise</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<?php
error_reporting(E_ALL);
//echo "<pre>" . PHP_EOL;
$database = "jch";
$user = "jch";
$password = "password";
$connector = 'jch.55.com';
$link = mysql_connect($connector,$user,$password);
mysql_select_db($database) or die( "Unable to select database");
$filter = $_POST["filter"];
$uploaddir = '/uploads';
$path = $uploaddir . $filter . basename($_FILES['ufile']['name']);
if($ufile != none)
{
if (move_uploaded_file($_FILES['ufile']['tmp_name'], $path)) {
echo "File is valid and was successfully uploaded.\n";
$row = 0;
if (($handle = fopen($path, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
$row++;
if( strlen($data[4]) > 0 )
{
$monitor_id = $data[1];
$time = date("Y-m-d H:i:s", strtotime($data[0]));
echo('<p>' . $time . ' rows processed: ' . $row . '</p>');
$noise_level = $data[2];
$flight_id = $data[4];
$aircraft_type = $data[3];
$query="INSERT INTO jch_noise_detail_copy (
monitor_id,
time,
noise_level,
flight_id,
aircraft_type)
VALUES(" .
"'" . $monitor_id . "','" .
$time . "'," .
$noise_level . ",'" .
$flight_id . "','" .
$aircraft_type . "')";
$result = mysql_query($query);
if( mysql_errno($link)!= 0 ){
echo $query . "\n";
echo mysql_errno($link) . ": " . mysql_error($link) . "\n" ;
}
}
} // end while
mysql_close();
}
}
else
echo 'No Rows found matching this date or filter';
}
mysql_close();
fclose($handle);
?>
</body>
</html>