Jasper
Jasper

Reputation: 5238

How to make a download page

I'm excited on how to do the download page similar to premiumpixels.com

Example - http://www.premiumpixels.com/freebies/custom-audio-player-skin-psd/

If we click on "download":

1) page reloads to url like premiumpixels.com/download/?file=audio-player

2) after some timeout download begins.

3) file downloads from cdn.premiumpixels.com/uploads/audio-player.zip

How do I make the same? How its done on php?

Also, I would like to send some mysql request when download page is opened, to update file downloads stats.

Thanks.

Upvotes: 2

Views: 6484

Answers (4)

Eric Falsken
Eric Falsken

Reputation: 4934

Or even a simple meta tag refresh in your page header:

<meta http-equiv="refresh" content="5; url=http://example.com/myfile">

Upvotes: 0

Erik A. Brandstadmoen
Erik A. Brandstadmoen

Reputation: 10588

Or, you could use a response of type MIME/Multipart, where you send the HTML page in the first part, and the file in the other part, then you don't need to use javascript at all :)

Upvotes: 0

cweinberger
cweinberger

Reputation: 3588

1.) User clicks on a link - e.g. download.php?id=my-app-id;

2.) In download.php you do your fancy mysql update stuff

3.) Then you redirect to the actual download file: header("Location: /folder/for/downloadcontent/download.zip");

For SEO Friendly urls use RewriteRule in .htaccess file

Upvotes: 2

tster
tster

Reputation: 18237

Use Javascript's setTimeout function and then redirect the browser to the download resource.

Looks like this is the source that site uses:

jQuery(function () {

    // get the GET variables
    var theme = getUrlVars();

    var downloadLink = 'http://cdn.premiumpixels.com/uploads/' + theme['file'] + '.zip';

    if(theme['file'])
    {
         jQuery('#downloadLink').attr('href', downloadLink);

         delayedDownload();
    }

    function delayedDownload()
    {
         timeoutID = window.setTimeout(downloadTheme, 1000);
    }

    function downloadTheme()
    {
        window.location.replace(downloadLink);
        //window.open(downloadLink,'','menubar=1,location=1,toolbar=1,width=600,height=500');
    }

    // Read a page's GET URL variables and return them as an associative array.
    function getUrlVars()
    {
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

        for(var i = 0; i < hashes.length; i++)
        {
            hash = hashes[i].split('=');
            vars.push(hash[0]);
            vars[hash[0]] = hash[1];
        }

        return vars;
    }

});

Upvotes: 2

Related Questions