iheartLUHAN
iheartLUHAN

Reputation: 63

how to retrieve a content of a table in database(with html tags)

i have made some inputs in my database table and it is saved together with its html tags. now, i want it to be downloaded by a user. i want to remove the html tags. Since the file input at my database table has no format, i want the download file to be downloaded as a document file and must be compatible in MS word.

so far i have this for the download page

<?php
if(isset($_GET['id']))
{
include 'connect.php';


$id    = $_GET['id'];
$result = mysql_query("SELECT title, content, format FROM activity WHERE id = '$id'");

list($title, $content, $format) = mysql_fetch_array($result);
strip_tags($content);
header("Content-type: $format");
header("Content-Disposition: attachment; filename=$title");
echo $content;

mysql_close;
exit;

}

?>

Upvotes: 0

Views: 141

Answers (1)

niconoe
niconoe

Reputation: 1321

There are more than one only problem on your script:

First of all, if you're sure there's only 1 value return by your query, add LIMIT 1. Then, to return your value, use $contents = $result[0]['content'];

Moreover, filename is the filename, not the content. Finally, read some docs about HTTP headers: Content-Disposition is not sufficient to send your file, even you're wanted to be compatible with MSword...

"the download prompt will appear. and the i download the file. and i open it in MS WOrd, it shows the content i saved with the html tags" => maybe you just htmlentities your tag in the database. Try this:

<?php
strip_tags(html_entity_decode($contents));
?>

Upvotes: 1

Related Questions