Is there any way I can prevent simultaneously multiple downloads from my site with PHP? I mean I want a user can download only 1 file at a time, the second file can be downloaded only after the first one is finished.

Thanx in advance for the help.

12 Years
Discussion Span
Last Post by digital-ether

You can use php to initiate the download for you, instead of linking directly to your files.
Also used to prevent "file leeching".

Theres a few examples here: http://us2.php.net/header
Look at the user contributed comments.

What you can do either write to a database, or flatfile when a file is being downloaded.

a user clicks to download your file.zip from the php script url:
Your php script will open a stream to the file that needs to be downloaded, then send that same stream to the browser. (using fopen or fsockopen etc. see: http://us2.php.net/fsockopen )
Your php script then needs to send the appropriate headers to the browser, to let it know that this is a file download (not a regular html page). see: http://us2.php.net/header
Your php script then writes to the database, or flat file, that this file is being downloaded by a certain user with certain session id. see: http://us3.php.net/session

When the user is downloading, you can have a flag that says so. The flag can be removed when the download is done.

So what you write to say a db would be.

"insert into current_downloads set session_id = $session_id, file_id = $file_id, status = 'downloading'";

When you're done you just update the status:
"update current_downloads set status = 'done' where session_id = $session_id and file_id = $file_id";

something along those lines...

hope thta helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.