0

So the process that I have goes like this. A user can pick a date range to view the data that he wants/needs. A Download is then available if he wants to download the file.

When doing a wide range the page throws off a connection error.

Firefox - The connection was reset

Chrome - No Data Received

The code that I use to generate the CSV is

<?php
$res = // the array generated by a mysql query
$text=strtotime("Now");
$filesave=fopen('Downloads/CallLogs'.$text.'.csv','w');
foreach ($res as $display)
{    
fputcsv($filesave,$display);
} 

//Force download the file. you can correct me if this is the improper way of doing it :)

header('Content-Type: application/download');
header('Content-Disposition: attachment; filename="CallLogs'.$text.'.csv"');
$fp = fopen("Downloads/CallLogs".$text.".csv", "r");
fpassthru($fp);
fclose($fp);
?>

Thanks in advance...

Alexis Zenigata
  • 157
  • 1
  • 1
  • 10
  • This question seems like the right way to create the csv file: http://stackoverflow.com/questions/217424/create-a-csv-file-for-a-user-in-php – GrayB May 08 '13 at 23:28
  • Try using `php://output` as your filename, and executing the fputcsv() loop after your headers rather than writing to disk first and then using passthru... has the added benefit of not leaving a file cluttering up the filesystem, and of allowing multiple concurrent requests without worrying about strtotime("Now") returning the exact same values – Mark Baker May 08 '13 at 23:31
  • the first code was the original code I used and it will only let me download 3 days worth of data. Talking about 50K rows and it doesnt work – Alexis Zenigata May 08 '13 at 23:33
  • 1
    Then check for timeout problems – Mark Baker May 08 '13 at 23:39
  • As @MarkBaker points out, you are probably running into timeouts or other resource limits. – tucuxi May 09 '13 at 01:28
  • got that thanks.. will check this info out.. – Alexis Zenigata May 09 '13 at 16:55

0 Answers0