I have large txt file(1GB), and allow user to download with 2 formats, TXT and CSV
I create download.php file.
$file = $_GET['file'];
$type= $_GET['type'];
$pathfile = "/some/path/".$file.".txt";
$isifile = file_get_contents($pathfile);
if($type == "TXT"){
header('Content-disposition: attachment; filename="'.$file.'.txt"');
header('Content-type: text/plain');
echo $isifile;
}else if($type == "CSV"){
$arr_file = explode("
", $isifile); //will die here because array need large memory
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=".$file.".csv");
foreach($arr_file as $wd ){
echo $wd;
}
}
The code is work for small txt file.
But it not work for large file.
Thanks