PDA

View Full Version : How to open a download dialog?


jdavidw13
12-05-2002, 11:15 PM
Hi,
In my php script I do this:

print("<meta http-equiv="Refresh" content="1; URL=testdir/file.mrc">");

what I want this to do, is for the web page to automatically pop open a download dialog. Instead it displays the file, it looks real messy because it isn't scrictly a text file. How do I get the download dialog to automatically come up when I load the page? Is there a way to do it in php or javascript? Anything would help,

Thanks,
JD

firepages
12-06-2002, 02:00 AM
header("Content-type: application/octet-stream");
readfile('testdir/file.mrc');

saved as download.php (or whatever) may do the trick ??

boywonder
12-06-2002, 11:53 PM
If nothing else worked you could zip the file.
Not sure if that would suit your purposes though...

ConfusedOfLife
12-07-2002, 08:48 PM
If nothing else worked you could zip the file.

I think it's the best way too! it's simple and certain!
Anyway, I saw this in PHP mans and it worked for me, but what firepages said doesn't work, it just reads a file and writes it into the page. I didn't know that even in PHP we have to take care of different browsers! yak, don't they wana remove this incompatibilities?
Go and read the PHP mans, you'll find tons of info, but I couldn't understand most of them!! It wasn't bad if anyone knew of a tutorial of the difference between all these headers.
Anyways, here is the code that I took from the php mans:

<?php
// We'll be outputting a PDF
header("Content-type: application/pdf");

// It will be called downloaded.pdf
header("Content-Disposition: filename=ourDownload!.pdf");

// The PDF source is in xml.pdf
readfile('xml.pdf');
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
.
.
.