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

Recommended Answers

All 2 Replies

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. :)

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

-James

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.