starvos
06-15-2010, 02:48 PM
I have some text files on the server in table format(columns & rows) and I used the following script to download it to my pc:
$path = $_SERVER['DOCUMENT_ROOT']."/lib/reports/"; // change the path to fit your websites document structure
$fullPath = $path.$_REQUEST['dlfile'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
header("Content-length: $fsize");
while(!feof($fd)) {
$buffer = fread($fd, $fsize);
echo $buffer;
}
}
fclose ($fd);
exit;
However, when I opened the downloaded text file, it gives me a long string of data instead of the columns & rows format. Can someone advise me how to rectify this?
$path = $_SERVER['DOCUMENT_ROOT']."/lib/reports/"; // change the path to fit your websites document structure
$fullPath = $path.$_REQUEST['dlfile'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
header("Content-length: $fsize");
while(!feof($fd)) {
$buffer = fread($fd, $fsize);
echo $buffer;
}
}
fclose ($fd);
exit;
However, when I opened the downloaded text file, it gives me a long string of data instead of the columns & rows format. Can someone advise me how to rectify this?