#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    41
    Rep Power
    35

    Question downloads manager system


    I am in the market for a downloads manager/system/controller for my website and I can't find anything anywhere that suits my needs. I am really hoping that someone here can point me in the right direction.

    I want something similar to fileplanet.com or fileshack.com.

    - I have a number of site members already registered
    - I want to offer them downloads on a somewhat restricted level.
    - - - a limited number of general members can download at one time. all others are placed in a queue
    - - - general members can only download one file at a time
    - - - general members have a cap on download speed
    - - - preferred members have no limit

    That's really all I need, but I can't seem to find a solution. I am a php and html programmer and those two languages just aren't cutting it here. I am thinking I need something like javascript or perhaps an applet.

    I am limited to running on a unix (Redhat) server so IIS is out.

    help.... please
  2. #2
  3. Moderator Emeritus
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2002
    Location
    Austin, TX
    Posts
    7,186
    Rep Power
    2265
    I am a php and html programmer and those two languages just aren't cutting it here.
    If you're a PHP developer, all of this could be coded in PHP; I'm not quite sure why you think you wouldn't be able to do this in PHP.

    None of the features you described need to be client-side (i.e. Javascript or Java Applet); all of this could be server-side.

    Have you checked Sourceforge for an app like this?
    DrGroove, Devshed Moderator | New to Devshed? Read the User Guide | Connect with me on LinkedIn
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    41
    Rep Power
    35
    yup... checked sourceforge, hotscripts, scriptsearch, phpclasses, etc.

    If it's possible to do this in php, then I have been mislead. Based on all of my test programming and responses in various forum posts, I can't do what I am looking to do.

    based on tests, php can't
    - limit the speed of a file download
    - estimate the connection speed to determine remaining download time
    - determine how much of a file has been downloaded to know how much is left

    php can read a file using fread (or something similar), but the resulting download of, let's say, a zip file ends in a corrupted file. All of the bytes aren't read during the download.

    I have come very close to a reliable script to limit the number of simultaneous downloads, but it's somewhat unpredictable in special circumstances. I can't be sure which circumstances, but sometimes when a download is cancelled, the server doesn't realize it.

    If I am wrong, I would love it. It would mean that what I am trying to accomplish can be done.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    12
    Rep Power
    0
    I searched high and low ( and still am to certain extent) for just such a system. About the only thing I came across was etreed.

    It certainly has the all the basic elements of what your asking, and gives good examples on how to write a proper file delivery system. I started on abstracting the code but never got around to fully implementing it.

    Let me know if you find it useful.. or if make anything out of it as I would certainly be interested.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    1
    Rep Power
    0

    i have a solution for the php download problem


    hi, i have a solution for you php download problem. lmk if you still need it.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    41
    Rep Power
    35
    Actually, I FINALLY found a solution to the situation. It was a long road, but I've got it all working now.

    Still, I appreciate that you left a message here.

    Looking for something even for sale isn't an option since there is nothing out there.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    12
    Rep Power
    0
    Any chance either of you could let me have any details of the systems that you've come up with..
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    41
    Rep Power
    35
    I will share and hopefully this will help and not confuse.

    a little background:
    I am running two servers. One webserver and one fileserver. I wanted to perform the action I described in earlier posts and also create a system to mask the actual location of the file so that it couldn't be leeched.

    To fix the leeching, I am creating links on the fly. These links are a combination of file id, user id, a little random math and most importantly the time the link was created. This way the link is only good for 3 minutes and then it expires and the page has to be reloaded for another link to download the file. That solved the problem of the leechers.

    Now for controlling the file during download:
    - I am running 3 files.
    - 1 gets the information about the file and reports any errors after decoding the 3 minute link. It also determines if the user is allowed to download the file (if they are a registered member with an active account). If no errors, then the user is entered into the database for the next process:
    Code:
    INSERT INTO tres_downloads_serv (dl_start_time, dl_update_time, dl_remaining_time, dl_id, dl_link, dl_cat_folder, dl_title, dl_size, user_id, user_uname, user_email, user_status, max_connect, speed_multiplier, dl_status, serv_id, user_ip) VALUES ('".time()."', '".time()."', '".round($file_size/($speed_multiplier*1024))."', '$dl_id', '$dl_link', '$dl_cat_folder', '$dl_title', '$file_size', '$user_id', '$user_uname', '$user_email', '$user_status', '$max_connect', '$speed_multiplier', '2', '$id', '$_SERVER[REMOTE_ADDR]')
    - 2 determines if they have to wait online or if they can download the file right away. This is done after checking the database for how many users there and whatever other criteria you have specified.
    - if they have to wait online, then the page keeps refreshing and checking the database until their wait is over. They are then presented a link to start the download. This link is also only good for 3 minutes.
    - 3 downloads the file. I think this is what you are really interested in and I will go into more detail.

    The download page setups up the headers, download speed, and reads the files to the user. I determine the $ctype of the file which could be application/force-download as default. Here are the headers:
    Code:
    	header("Pragma: public");
    	header("Expires: 0");
    	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    	header("Content-Type: $ctype");
    
    	$user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);
    	if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent, "win")))) {
    		header( "Content-Disposition: filename=".basename($filename).";" );
    		} else {
    		header( "Content-Disposition: attachment; filename=".basename($filename).";" );
    		}
    	header("Content-Transfer-Encoding: binary");
    	header("Content-Length: $serv[dl_size]");
    little more info before the code:
    - To monitor the download in the database, I keep calling and updating the database during the download.
    - the speed multipler is a whole number (1,2,3,100,1000, whatever) and then must be multiplied by 1024. This is how large each chunk of the file is read. Pausing between these chunks limits the speed accordingly. so, 60*1024 in this program will allow about 60kbps download speed.

    Code:
    	$start_time = time();
    	$sessid = $start_time+30;
    
    	$sql = mysql_query("UPDATE tres_downloads_serv SET
    						dl_update_time    = '".time()."',
    						dl_remaining_time = '".($serv[dl_size] / ($serv[speed_multiplier]*1000))."',
    						user_ip           = '$_SERVER[REMOTE_ADDR]:$_SERVER[REMOTE_PORT]'
    						WHERE serv_id = '$id'");
    
    	$fp = fopen($filename, 'r');
    
    	$speed=($serv[speed_multiplier] * 1024);
    	while (!feof($fp)) { 
    		echo(fread($fp, $speed)); 
    		flush();
    
    		sleep(1);
    		if(time() > $sessid) {
    			$sessid = $sessid+30;
    			$currenty = ftell($fp);
    			$elapsed = time() - $start_time;
    			$time_left = ($serv[dl_size]/($currenty/$elapsed)) - $elapsed;
    
    			$netstat = eregi("$_SERVER[REMOTE_ADDR]:$_SERVER[REMOTE_PORT]", shell_exec("netstat -n |grep ".$_SERVER[REMOTE_ADDR].":".$_SERVER[REMOTE_PORT].".*EST"));
    			if(empty($netstat)) {
    				$sql = mysql_query("DELETE FROM tres_downloads_serv WHERE serv_id = '$id' AND user_ip = '$_SERVER[REMOTE_ADDR]:$_SERVER[REMOTE_PORT]'");
    				die;
    				}
    
    			$sql = mysql_query("UPDATE tres_downloads_serv SET
    								dl_update_time    = '".time()."',
    								dl_remaining_time = '$time_left'
    								WHERE serv_id = '$id'");
    			}
    		}
    	fclose ($fp);
    
    	$sql = mysql_query("DELETE FROM tres_downloads_serv WHERE serv_id = '$id'");
    
    	die;
    I hope that helps.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    12
    Rep Power
    0
    Just to let people know I've created a project for my version of a solution to this problem at Sourceforge.. its called Tramitto.

    I've already got a working solution to the problem above, with queing etc in and I hope to have this released over the weekend.

    I'm now extending the idea even futher to implement a zipping system as well so that users can request a directory, the system will zip the files in the directory and send the zip file instead.

    If you want to help email through the sourceforge site.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    5
    Rep Power
    0
    I have actually just done something similar.

    It is without file queing or speed limiting, but manages files.

    Im still building the usersystem, which enables users to add information to files in there folders on the server, as i run a extreme sport video hosting site.

    It can be seen at http://www.trials-shack.co.uk

    It is still very much young, and has some problems, one which one of you might actually have solved, so thought this might be a good place to ask .

    Basically, my system uses .htaccess to load up a html page when you click a link to a video. You then click a button, which uses $_POST then some header() and fp()'s to load up a save dialog box.

    However, because i host videos, some people use "download resumers". If you have heard of these, they basically can pause/restart downloads from where you stopped/got disconnected from.

    But ofcourse, when the programs requests the video again, it isnt there as its a php page. So if anyone uses .htaccess in there scripts, and finds a solution for the resuming, please share
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    41
    Rep Power
    35
    Since I limit the age of each download to prevent leaching... I don't allow download managers to run. In a sense, What I have created is a download manager.

IMN logo majestic logo threadwatch logo seochat tools logo