How can I create the "Download will begin soon" page?

I would like to create a PHP page that displays a message like

Your download will begin shortly.

If it does not start, please click here to restart the download

that is, the same type of page that exists on major websites.

It will work as follows:

<a href="download.php?file=abc.zip">Click here</a>

When the user clicks on this link, he gets the file download.php, which shows him this message, and then offers the file to download.

How can i do this?

Many thanks!

+5
source share
3 answers

The link should do one of two things:

"" - META REFRESH.

JavaScript, , ( Mozilla Firefox):

function downloadURL() {
    // Only start the download if we're not in IE.
    if (download_url.length != 0 && navigator.appVersion.indexOf('MSIE') == -1) {
        // 5. automatically start the download of the file at the constructed download.mozilla.org URL
        window.location = download_url;
    }
}

// If we're in Safari, call via setTimeout() otherwise use onload.
if ( navigator.appVersion.indexOf('Safari') != -1 ) {
    window.setTimeout(downloadURL, 2500);
} else {
    window.onload = downloadURL;
}
+2
<?php
// download.php
$url = 'http://yourdomain/actual/download?link=file.zip'; // build file URL, from your $_POST['file'] most likely
?>
<html>
    <head>
        <!-- 5 seconds -->
          <meta http-equiv="Refresh" content="5; url=<?php echo $url;?>" />
    </head>
    <body>
        Download will start shortly.. or <a href="<?php echo $url;?>">click here</a>
    </body>
</html>
+2

If you want to be sure that the file will be downloaded (unlike the one shown in the browser or browser plug-in), you can set the Content-DispositionHTTP header . For example, to make PDF files load instead of opening in a browser plugin:

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="foo.pdf"');
readfile('foo.pdf');
0
source

All Articles