Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force .xls download

Status
Not open for further replies.

travisbrown

Technical User
Joined
Dec 31, 2001
Messages
1,016
How does one force an .xls download of a table in php? I have a tab-delimited text file that I need to open as an excel. I'm not sure how one writes headers with PHP.

Code:
<?php 
$file = "registrants.txt";
$fp=fopen($file,'r');
$content=fread($fp,filesize($file));
fclose($fp);

$content = "<table><tr><td>".$content."</td></tr></table>";
$content = str_replace(chr(10),"</td</tr><tr><td>",$content);
$content = str_replace(chr(9),"</td><td>",$content);

echo $content;
?>
 
This gives the user the option to open or save a comma seperated volume:

Code:
<?php
header('Content-type: application/excel');
header('Content-Disposition: attachment; filename="downloaded.csv"');
readfile('my.csv');
?>

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top