954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

HTML with download headers

I have a great download script I have been using from: http://www.zubrag.com/scripts/download.php . It uses the following headers:

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: $mtype");
header("Content-Disposition: attachment; filename=\"$asfname\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $fsize);


My goal is to call this php download file, which will display some initial html information then begin the download... similar to 'your download should start momentarily, otherwise click the following link'. The problem is that when I place the html code before the download code in this file, the contents of the file are displayed by the browser in binary (rather than starting the file download).

Is it possible to do this, or am I way off base? Any suggestions will be greatly appreciated.

Thanks,
James

jimmiller96
Newbie Poster
21 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

Instead of directly calling download.php?id=144, once you have the info, pass the id=144 to a go-between page, downloadprep.php, or whatever strikes your fancy, before invoking the download.php script:
downloadprep.php?id=144

<?php $id = $_GET['id']; ?>
<html>
<head>
<title>Your download will start momentarily...</title>
<script>
  function startDownload() {
    location.href='download.php?id=<?php echo $id; ?>';
  }
</script>
</head>
<body onLoad="startDownload()">
<p>Here it comes!</p>
<p>...otherwise, click <a href="download.php?id=<?php echo $id; ?>">here</a>.</p>
... other stuff you want to display ...

</body>
</html>


My 2ยข. Hope this helps. :)

Wraithmanilian
Junior Poster
196 posts since Dec 2009
Reputation Points: 17
Solved Threads: 42
 

Doh! Didn't even think of that. Worked like a charm. Thanks for the quick response... and example!

-James

jimmiller96
Newbie Poster
21 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: