The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

The download counter should only spin if the link has really been clicked or the download has started. At the moment I'm having a redirect to another download.php3 page which counts the counter up by one.

Another problem is that the download doesn't start. How do I automatically let a download begin when redirected to this page?

Making a download begin is as simple as including a META refresh tag in the HEAD of the confirmation screen (generated by your counter increment script):

Code:

<META HTTP-EQUIV=refresh CONTENT="0;URL=thefile.zip">

As for only incrementing the counter if the download actually happens, the solution there is to make the counter script actually send the requested file to the browser. Use a call to header() to tell the browser what MIME type to receive, then use readfile() to send the contents of the file to the browser.

Originally posted by kyank As for only incrementing the counter if the download actually happens, the solution there is to make the counter script actually send the requested file to the browser. Use a call to header() to tell the browser what MIME type to receive, then use readfile() to send the contents of the file to the browser.

Sorry for this dump ques, but..... how can I do this? If possible can you provide me with some code?

The file size can be set with an HTTP header (I'll have to look it up when I get home if nobody else comes up with it before then). I've heard the file name can be too, but I've never had opportunity to try. I'll try to find an appropriate header for that, too.

You definitely don't want to use a URL for your filename -- this slows things down tremendously, as PHP retrieves the file using an HTTP download (masquerading as a browser requesting the file from your Web server) rather than just opening it directly from your hard drive.