Download a TXT
Posted: Sun Feb 10, 2008 1:01 pm
Hi everybody,
Im been triying to create a function/code that help me to download an article from my database into a txt... This what i got so far..
The download its fine but when i open the file i get this:
Thanks
Im been triying to create a function/code that help me to download an article from my database into a txt... This what i got so far..
Code: Select all
<?php
include "config.php";
$id = (isset($_GET['id'])) ? intval($_GET['id']) : 0;
if(!empty($id)){
$result = mysql_query('SELECT `id`, `page`, `header`, `date`, `content`, `contador` FROM `webapp`');
$filename = "$id.txt";
// Push headers that tell what kind of file is coming down the pike
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename='.$filename);
$content=$row['content'] . (strlen($row['content']) < 256 )? str_repeat('\n',256-$total):''; // Fix annoying IE bug
$total = strlen($row['content']);
header('Content-length: '.$total);
echo $content;
} else {
die('Unknown File');
}
?>Why this happens?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Thanks
