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

Logic question
im wondering what's the best method to do the above list:

it is for alliance @ MMORPG game

php web service error
hey guys,
I'm working on a project requires the use of web services. I've been trying a few tutor

undefined offset help
Hi All,

I kept getting undefined offset PHP notice for a simple for loop. For eg
$va = arr

Date Question
I'm using the TIMESTAMP() function within mysql to set the date/time for certain events. However, ho

upload form file types....
Hey all, I am learning PHP and I am writing a script from the W3C Schools tutorials for uploading fi

simple script won't work. Please help
I'm new to php, and I am having trouble displaying a simple script in my web browser. My php code ex

rdns with php
I am trying to build a script that will show all of the different domains that are hosted on the sam

PHP MySQL Return Results Issue
Hi guys,

I'm running joomla and made a module which is using ajax.
Basically i just have a

SESSION CHECK WORKS "MOST" of the time... whats going on?
i have a sign in check thats included in every page that is a members only page which is basically a

Help =( !! Upload Pics [PHP script]
Hello
I need help with a php script [MULTIPLE UPLOAD IMAGES] , where I want to add a feature (wat

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