Link to home
Start Free TrialLog in
Avatar of dmehran
dmehranFlag for United States of America

asked on

recording download stats with PHP (Download Manager)

Hi,

I have a PHP script that allows users to download a zip-file. I need to build a download manager or have a way of recording some stats such as complete downloads, partial downloads, etc. Is there a php library that anyone could recommend me for doing this? If I have to write this myself, could I get some hints as what this involves?

Thanks
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

I don't know of a library, but it might be pretty easy to write the script.  You would keep track of this in a data base table.  The general logic would go like this.

The data base table has fields dl_id (AUTO_INCREMENT), dl_user_id, dl_start (DATETIME), dl_end (DATETIME), dl_filename

1. Add a record to the table with the user-id, the current timestamp and the name of the file that is to be downloaded.
2. Start the download
3. Upon completion, update the record you just added to fill in the timestamp when the download completed.

Then you can query that table to find any rows with an empty "dl_end" and you'll know of incomplete downloads.  You can also find which users have downloaded which files, etc.

HTH, ~Ray
Avatar of dmehran

ASKER

Ray,

Thanks for replying to my question. I am aware of database solutions to record the data. The part I am having difficulty with is detecting when a download starts and more importantly when download completes. How is that done? I can implement a front end solution in Flash to monitor the downloaded data packets vs the total file size; as a matter of fact Flash does have a FTP component with provided methods that I can use to monitor file upload/download. However we are looking for a server side solution. The company I work for doesn't rely too much on front-end solutions such as flash for a remote chance that a user may not have flash installed. A server solution at this point to detect the start and completion of a file download is what I am looking for at this point.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The reason for the session_start() statement is that I was thinking of adding a key to the GET string and storing it in the session, then testing it in this script to see if the GET key matched the SESSION key.  It's a minor security step, probably not needed at this point in the proof of concept stage.
Avatar of dmehran

ASKER

Thanks!!! I'll try this and will let you know
Avatar of dmehran

ASKER

With some modifications I got this work. Had to modify the solution to tailor it to my application. Thanks for the solution.