downloading a file as HTML


Posted on 16th Feb 2014 07:03 pm by admin

Hi.
I'm rather confused with forcing a download. I just want to save dynamic content (from $_SESSION[''] data) as a .html file.

The script to do this is a PHP page, but when I click on "download" it downloads as "download.php"

Here's the code:
Code: header("Cache-control: private"); //IE 6 Fix

if (isset($_GET['download']) && $_GET['download']=="true" && isset($_GET['filename']) && $_GET['filename']!="") {

// retrieve content of the file here, e.g. from a database...

$content=$_SESSION['old_page'];

// send the header here
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="' . $_GET['filename']);

// put the content in the file
echo($content);

// stop processing the page
exit;
}
It's accessed using: Code: <a href="../outputs/download_as_file.html?download=true&amp;filename=shine_output.html">Download</a>
Any suggestions? I found a good tutorial here: http://richardlynch.blogspot.com/2006/06/php-downloads-content-disposition.html but don't think it'll do what I need to do

No comments posted yet

Your Answer:

Login to answer
73 Like 10 Dislike
Previous forums Next forums
Other forums

writing a screen scraper
Hello,

I'm writing a screen scraper application and want to be able to get absolute addresses

Cache PHP Objects/Classes?
Does anyone have ideas about caching PHP objects using something like: http://memcached.org/

http to https
Hi,

Is there any specific method/condition to move an http:// page to https:// ?

Stumped by Third Day of Month problem
I am trying to build an algorithm that will essentially do this:
Code: [Select]$this_month = Oct

help with mysql_error()
Hi,

I am trying to insert data into a table, but I am not able to insert it. I wanted to see

[PHP HELP] Php order form.
Hello to everyone @ phpfreaks. Im new to this site and hope to learn lots of things here.

Fir

Issue Parsing XML into table
Hello all,

Im a bit new to php and new to phpfreaks. But thanks in advance for the help!
<

str_replace help
Hey there,

I'm a PHP newb, I'm having troubles with the str_replace function. I want to clean

output printing as hexadecmal... XD
Everything works except the calcem call for the totusold and totuprice. The out put shows up as hex.

Need help making login verification cleaner...
I use the below to verify user login. I first check the cookie for the id, ip and a unique id. If it

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash