3

I am creating a script to keep download statistics, but I would only like to update the stats if the file was ACTUALLY downloaded.

The problem is that browsers (e.g., Explorer 9, Chrome, ...) automatically start downloading the file while the 'save/open' dialog is still open. This means the file can completely download (into a browser specified temp directory I assume) before the user has specified where to save it (or while Explorer still shows the Yellow warning bar).

The user may decide to cancel the save, even though the file was successfully downloaded. How can I tell browsers not to automatically start downloading? Some HTTP header perhaps? Any other solutions?

Arie Livshin
  • 865
  • 1
  • 12
  • 26
  • 2
    You got something wrong here, whether the user specifies to save file somewhere or not, the ACTUAL transfer occurred, even if the file was stored in the temporary directory and user later on decided to press "Cancel". Also, what's the purpose of going so deep into finding out whether someone pressed the "Save" button or not, what can that statistic tell you that's of vital importance to business? – Michael J.V. May 02 '11 at 10:34
  • Maybe I didn't explain very well. I need to check how many users downloaded our software (and pay for these downloads) vs. how many users actually install it. If a user pushed the download button and then cancelled, it should not count as a download. Unfortunately due to browser cache/prefetch of downloadable files, I do not know if the user actually downloaded the software and may someday install it, or it's just the browser mechanism. – Arie Livshin May 02 '11 at 12:52
  • 1
    Then your approach to the problem is wrong. If someone paid for the download, they should be able to download the file at any point during the period their licence is valid, you shouldn't make it such that the download link is valid once. – Michael J.V. May 02 '11 at 13:53
  • Michael, I'm afraid you miss the point here. Users don't pay for the download, I am the one who pays the advertisers for COMPLETE downloads. The question is technical, not business. Please see Brad's reply below for more details. – Arie Livshin May 03 '11 at 12:55
  • I have a quite strong answer from here! check-it-out. [http://stackoverflow.com/questions/1563187/check-if-download-is-completed](http://stackoverflow.com/questions/1563187/check-if-download-is-completed) – Sahan Jan 16 '17 at 06:06

3 Answers3

3

You can't do what you are wanting to do. It is impossible, at least in the way you are asking.

What you can do is put some code in the installer that reaches out to your server when it runs, and your script can keep track of it then. This is commonly done, but is certainly not foolproof. Many people download software and install offline. (Particularly, dial-up users, which are still out there by the thousands.) Also, there is no guarantee that the installer won't be blocked by firewall software or something.

So this all depends on how bad you need to know when it was installed. If it is critical, then your installer needs to verify with the server before installing. Of course this can be hacked around, and there is nothing you can do about it. But, I suspect it will work for your purposes.

Also, don't forget about multiple installs per download.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • Yes, when the installer runs, it sends a message to our server. The problem is that the number of downloads is 5 times bigger than the number of these messages we receive from the installers, so downloads get lost somewhere. My first suspicion is exactly the problem I wrote about - users cancelling downloads. – Arie Livshin May 03 '11 at 12:52
  • 2
    @Arie Livshin,... or resumed downloads, or download managers splitting the file into pieces, or anything really. – Brad May 03 '11 at 13:11
  • I have the downloader's IP. So in cases of resumed downloads, or split downloads, I can see that the same IP downloaded the file several times, and count this ip just once. – Arie Livshin May 03 '11 at 15:04
  • 2
    @Arie Livshin, not really. Don't forget that many users can share the same public IP. – Brad May 03 '11 at 15:48
  • 1
    @Arie Livshin, if your downloads are available without authentication, don't forget about bots and such. – Brad May 03 '11 at 15:50
  • We use robots.txt, but I understand some spiders may ignore it. – Arie Livshin May 04 '11 at 08:38
  • @Arie: and to add: there are many users behind a proxy who get a new IP address every time they log on the internet. – Marcel Korpel May 04 '11 at 08:50
0

I don't think you can see this. You'll have to let someone pay for the software before sending it to the client.

And I suggest you let the site remember the purchase, so if something went wrong during the download, a user can retry, without having to pay again (or contacting an administrator).

Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
  • We pay advertisers for the number of downloads from their site, and when a user pushes the link to our software and then cancels, we need to know. – Arie Livshin May 02 '11 at 15:31
  • @Arie: you can't. On a fast connection, the file might be actually downloaded before the users chooses ‘Save’ or ‘Cancel’. – Marcel Korpel May 02 '11 at 15:42
  • Exactly my problem and my question. Is there a way perhaps to prevent the browser from doing such background downloading? – Arie Livshin May 03 '11 at 12:48
  • 1
    @Arie: again: you can't. It's not the browser that does the background downloading, it's how HTTP works *by design*. Immediately after the headers are sent the actual bytes of the file must be output. – Marcel Korpel May 04 '11 at 08:51
0

Well, having some sort of intermediate page to confirm "yes I want to download this" may mostly eliminate canceled downloads.

Now, I'm not sure this is entirely possible, but you may try to serve the file via PHP, instead of the typical download from Apache. In PHP, you can use readfile to serve a file from the PHP script. So, you may be able to call readfile, flush, and determine the number of bytes served. If that doesn't equal the number of bytes in the file, it was interrupted. I'm not sure if readfile works like that, but its worth experimenting with.

Note, that still won't fix what Marcel mentioned, about hitting 'Cancel' before the tempfile download completes.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • 1
    I am using a PHP and readfile. The problem is that the browser actually downloads the file in the background even before the user gives her confirmation, so the PHP thinks the file was downloaded. Is there a way to prevent the browser from doing such background download, or tell whether the user saved or not? – Arie Livshin May 03 '11 at 12:50