How can I make a download page?

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.

  • Answer:

    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; } });

Steve at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

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

harakiri

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

Erik A. Brandstadmoen

Or even a simple meta tag refresh in your page header: <meta http-equiv="refresh" content="5; url=http://example.com/myfile">

Eric Falsken

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.