I am experiencing some weird behavior when using the following function:
function Push_File($Filename, $QUERY) {
$NUM_FIELDS = mysql_num_fields($QUERY);
header("Pragma: cache");
header("Content-Type: text/plain");
header("Content-Disposition: attachment; filename=".urlencode($Filename).".csv");
while ($Data = mysql_fetch_array($QUERY, MYSQL_NUM)) {
unset($CSV_Data);
$CSV_Data = '';
for ($I=0; $I < $NUM_FIELDS; $I++) {
$CSV_Data .= "\"$Data[$I]\",";
}
$CSV_Data = substr($CSV_Data,0,-1);
echo $CSV_Data."\r\n";
}
}
The problem is, sometimes when I send a large query to the function (a query which should return about 4.5MB of data) it does not return all of the data, only 100KB sometimes, sometimes 1MB, and sometimes it delivers the whole 4.5MB of data.
Has anyone ever experienced this and maybe found a solution?
Thanks in advance,
Tom 🙂