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

Image loading
Hi Developers,

I'm trying to display an image from images/image.gif getting the url from mysq

Facebook status update API
Hello,

So, I'm trying to create my first Facebook application with PHP.

Basic ideas fo

what does this mean? +=
is anyone able to explain what this code is saying?

i had it written for me awhile back and n

Access website from only 1 computer...?
One of my customers wants his website to only be accessed by people in which they bought the website

Gantt Chart Tool
Does anyone know of a good free gantt chart creator tool

Thanks

is_dir() problem
Hello,

I'm buidling a php scripts that dynamically get's subfolders from a specific folder.

MS Exchange 2007 integration with ECC 6.0
Hello Experts,
We have ECC 6.0 and MS Exchange 2007. We need to integrate ECC 6 and MS Excha

How to load mysql (and other) extensions into PHP
How to load mysql (and other) extensions into PHP PHP Development forum discussing coding practices,

Form help: Syntax & Logic
Hello again all,

I'm working on a form and ran into a wall (again) and can't seem to think th

Multiple server callbacks (NOT POSTBACKS)
Hello, I have 2 different javascript client side functions that are on timers. When the timers elap

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