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

search query in mysql in php problem
my search query wont work, i know, that my codes are correct.please help

Code: [Select]&l

Array disappearing in foreach loop
Okay, I have this problem where an array will become undefined in a foreach loop.

Here is the

Baffled by Undefined Index in Simple Array: Please Help!
Hello. I have a form which posts an array to this script. However, I can't seem to access the values

using variables in another page
I have a test database set up on localhost. I have a form that I can type a name into, hit the butto

Final year project, please point me in the right direction
hi there for my final year project I'm aiming to build a php script shell to use as an expert system

download directory onto C drive
I am attempting (if this is possible) to write a routine to automatically dump the contents of a dir

Target costs on Process orders not calculating
Hi All,

We have released standard costs for all the materials. We have also done Goods r

DateObject and Nulls
Hi all,

I have an array mapped to a value object. One of the items in the array is a PHP Date

Accept only alpha characters
I've got this bit of code ready for accepting a phrase:

Code: if (!eregi ("", $_POS

Please help with SMTP Authenticated PHP Email Form
Hello, I'm creating a PHP email form, and for this particular server, I have to use SMTP Authenticat

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