Download script needed

Status
Not open for further replies.

Ted

New member
Nov 4, 2006
88
2
0
Can anyone recommend a good download script, preferably in PHP

Basically all i want it to do is count the number of downloads and create a 20-30 sec delay from when someone clicks the link and when the download starts.

Any guidance would be appreciated.

Update: found a reasonable download management script, if anyone is looking for one I'll dig up the link for them. Now all i need is some code to convert a static link into a countdown before it becomes active. javascript or ajax ? hmmm
 
Last edited:


You don't really need ajax. All you need is javascript to do a countdown, and then when it's over, set the download link div from invisible to visible.

On the server side, you'll set a session variable with the datetime that the link will become active (now plus xxx seconds). If they try to get it before then, just deny them.
 
The download script I have buries the files in a non public directory so they must have the specific link to download the file.

I spent ages looking through google for the JS to do the countdown but all I could find was event countdowns and I don't think people are going to wait till xmas for their file :)

I'll keep looking !

I wish I was a programmers asshat.
 
Code:
// global variables
var targetInMS, timerInterval;
var oneSec = 1000;
   
// pass the number of seconds to count down
function startTimer(secs) {
    var targetTime = new Date( );
    targetTime.setSeconds(targetTime.getSeconds( ) + secs);
    targetInMS = targetTime.getTime( );
    // display starting image
    setImages(secs);
    timerInterval = setInterval("countDown( )", 100);
}
   
function countDown( ) {
    var nowInMS = (new Date( )).getTime( );
    var diff = targetInMS - nowInMS;
    if (diff <= 0) {
        clearInterval(timerInterval);
        alert("Time is up!");
        // more processing here
    } else {
        var scratchPad = diff / oneSec;
        var secsLeft = Math.floor(scratchPad);    
        setHTML(secsLeft);
    }
}
   
function setHTML(secs) {
document.getElementByID("countdown").innerHTML =secs;
}
   
function formatNum(num, len) {
    var numStr = "" + num;
    while (numStr.length < len) {
        numStr = "0" + numStr;
    }
    return numStr
}

// start the timer for 30 seconds
startTimer(30);

Note, the last line of the script is where you start the timer for a 30 second countdown.

Then, somewhere in the HTML, have:

<div id="countdown"></div>
 
Status
Not open for further replies.