Results 1 to 6 of 6

Thread: download script

  1. #1
    Join Date
    Dec 2004
    Posts
    55

    download script

    Hello,
    Is there any php scripts that allow me to restrict the user in downloading file? Let say i am able set user 1 can only download file 1, user 2 can download both file 1 and file 2 and etC?

    Thanks

  2. #2
    Join Date
    Feb 2005
    Location
    United Kingdom
    Posts
    3,104
    try hotscripts.com or you can ask some one to write for you this script.
    Low Cost Storage VPS plans at webprovps.com
    VPS Price Match Guarantee on: All our range of DDOS protected XEN HVM VPS
    == Contact us for any online solution development or managed / unmanaged vps hosting ==

  3. #3
    You could do it like this:

    You have 1 table "tbl_downloads" holding all downloads (id, filename, filepath).
    You have 1 table "tbl_permissions" holding permissions if a user is allowed to download file X (id, download id, user id).

    You search the table "tbl_permissions" if theres an entry for user $userID and download $fileID.
    If such an entry exists, the user is allowed to download the file.

    PHP Code:
    $fileID 1;
    $userID 1;

    $sql "SELECT  * 
            FROM    tbl_permissions 
            LEFT 
            JOIN    tbl_downloads 
            ON      (tbl_permissions.permission_download_id = tbl_downloads.download_id) 
            WHERE   permission_user_id     = '"
    .$userID."' AND 
                    permission_download_id = '"
    .$fileID."'";
    $read mysql_query($sql);
            if(
    $row mysql_fetch_object($read)) {
            
    header("Content-Type: application/octet-stream");
            
    header("Content-type: application/force-download");
            
    header("Content-Disposition: attachment; filename=\"".$row->download_filename."\";");
            
    header("Content-Transfer-Encoding: binary");
            
    header("Content-Length: ".filesize($row->download_filepath.$row->download_filename));
            
    readfile($row->download_filepath.$row->download_filename);
            exit;
            }
            else {
            echo 
    "You are not allowed to access this file!";
            } 
    To avoid direct access to the folder where the downloads are stored in, use a .htaccess file similar to this:

    <limit POST GET PUT DELETE>
    order deny,allow
    deny from all
    </limit>

  4. #4
    Join Date
    Oct 2006
    Posts
    59
    I imagine it would be something to do with storing a cookie in the person's computer - or storing their IP.

  5. #5
    Join Date
    Mar 2006
    Posts
    965
    You could also do it like this:

    PHP Code:
    $fileID 1;
    $userID 1;

    $sql "SELECT  * 
            FROM    tbl_permissions 
            LEFT 
            JOIN    tbl_downloads 
            ON      (tbl_permissions.permission_download_id = tbl_downloads.download_id) 
            WHERE   permission_user_id     = '"
    .$userID."' AND 
                    permission_download_id = '"
    .$fileID."'";
    $read mysql_query($sql);
            if(!empty(@
    mysql_num_rows($read)) {        
            if(
    $row mysql_fetch_object($read)) {
            
    header("Content-Type: application/octet-stream");
            
    header("Content-type: application/force-download");
            
    header("Content-Disposition: attachment; filename=\"".$row->download_filename."\";");
            
    header("Content-Transfer-Encoding: binary");
            
    header("Content-Length: ".filesize($row->download_filepath.$row->download_filename));
            
    readfile($row->download_filepath.$row->download_filename);
            exit;
            }
            else {
            echo 
    "You are not allowed to access this file!";
            }
            else {
            echo 
    "No content found.";
             }
            } 

  6. #6
    hotscripts.com is the best place to get new script

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •