this code works on my offline version in xampp and automatically downloads CSV file. But the same code doesn't work on my live website in Hostgator. Is there something that i should change? it just displays on the browser instead of automatically generating/downloading the csv file
$delimiter = ",";
$filename = "depot_".$direction. date('Y-m-d') . ".csv";
// Create a file pointer
$f = fopen('php://memory', 'w');
// Set column headers
$fields = array( 'Depot Ref','Container No', 'Container Type', 'Check-In Date', 'Storage');
fputcsv($f, $fields, $delimiter);
// Output each row of the data, format line as csv and write to file pointer
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
$storage=getStorage($row["depotRef"]);
$lineData = array( $row["depotRef"], $row['containerNo'], $row['containerType'],
$row['checkIn'], $storage);
fputcsv($f, $lineData, $delimiter);
}
// Move back to beginning of file
fseek($f, 0);
// Set headers to download file rather than displayed
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="' . $filename . '";');
//output all remaining data on a file pointer
fpassthru($f);
exit;
