Jump to content

Need help - php download from remote URL


foxclone
Go to solution Solved by Barand,

Recommended Posts

On my website, I have a download folder containing several files ranging in size from 6Mb to 700Mb. Users have no problems downloading the smaller files but often have problems downloading the files over 500Mb. We also have an archive of all the files located on a sub-domain on a server in England. Those users that are having problems downloading large files from the main site usually have no problem downloading the large files if we send them the URL for the archive. I've added a button that calls the following script so the users can choose where to download from but have no idea how to code the script.

Here's what I've tried:

// ukdloader script
<?php

$php_scripts = '../../php/';
require $php_scripts . 'PDO_Connection_Select.php';
require $php_scripts . 'GetUserIpAddr.php';
function ukdloader($l_filename=NULL)

{
$ip = GetUserIpAddr();
if (!$pdo = PDOConnect("foxclone_data"))
{    
    exit;
}

    if( isset( $l_filename ) ) {  
        echo <a href="http://foxclone.org/".$l_filename">   /* This is the archive site */
        
        $ext = pathinfo($l_filename, PATHINFO_EXTENSION);
        $stmt = $pdo->prepare("INSERT INTO download (address, filename,ip_address) VALUES (?, ?, inet_aton('$ip'))");
        $stmt->execute([$ip, $ext]) ; 

        $test = $pdo->query("SELECT id FROM lookup WHERE INET_ATON('$ip') BETWEEN start AND end ORDER BY start DESC, end DESC");
        $ref = $test->fetchColumn();
        $ref = intval($ref);

        $stmt = $pdo->prepare("UPDATE download SET ref = '$ref' WHERE address = '$ip'");
        $stmt->execute() ;         
       }
        
    else {
        echo "isset failed";
        }  
}
ukdloader($_GET["f"]);
exit;

Thanks in advance.

Link to comment
Share on other sites

4 hours ago, foxclone said:

Users have no problems downloading the smaller files but often have problems downloading the files over 500Mb.

Have you looked into why?

 

4 hours ago, foxclone said:

We also have an archive of all the files located on a sub-domain on a server in England. Those users that are having problems downloading large files from the main site usually have no problem downloading the large files if we send them the URL for the archive.

Are the geographically closer to England than the main site's servers? Because what you may be discovering is the concept of mirrors.

Link to comment
Share on other sites

@gw1500se - Are you proposing using the jquery as a solution to the download problem for large files or as a solution to download from the remote server?

@requinix - yes, that was the idea, to have a mirror of the main download folder. I've created two buttons, one to download from the U.S. site, and one to download from the U.K. site but don't know how to code the download link in the code I've posted for the U.K. site.

 

Link to comment
Share on other sites

@requinix - on the U.S. side, that's where the download happens. I just don't know how to code it to download from the remote server. Here's the code where the buttons calls these scripts which are located in the download folder:

<a href="download/usdloader.php?f=<?php echo $isoname;?>"><center><img src="images/us_download.png" style="height:44px; width:144px;"  alt="download iso"> </center></a> <br />    
<a href="download/ukdloader.php?f=<?php echo $isoname;?>"><center><img src="images/uk_download.png" style="height:44px; width:144px;"  alt="download iso"> </center></a>             

Here's the code for the U.S. side:

<?php

$php_scripts = '../../php/';
require $php_scripts . 'PDO_Connection_Select.php';
require $php_scripts . 'GetUserIpAddr.php';
function mydloader($l_filename=NULL)

{
$ip = GetUserIpAddr();
if (!$pdo = PDOConnect("foxclone_data"))
{    
    exit;
}
    if( isset( $l_filename ) ) {  
        header('Content-Type: octet-stream');
        header("Content-Disposition: attachment; filename={$l_filename}");

        header('Pragma: no-cache');
        header('Expires: 0');        
        readfile($l_filename);
        
        $ext = pathinfo($l_filename, PATHINFO_EXTENSION);
        $stmt = $pdo->prepare("INSERT INTO download (address, filename,ip_address) VALUES (?, ?, inet_aton('$ip'))");
        $stmt->execute([$ip, $ext]) ; 

        $test = $pdo->query("SELECT lookup.id FROM lookup WHERE inet_aton('$ip') >= lookup.ipstart AND inet_aton('$ip') <= lookup.ipend");
        $ref = $test->fetchColumn();
        $ref = intval($ref);

        $stmt = $pdo->prepare("UPDATE download SET lookup_id = '$ref' WHERE address = '$ip'");
        $stmt->execute() ;         
      }
        
    else {
        echo "isset failed";
        }  
}
mydloader($_GET["f"]);
exit;

 

Edited by foxclone
added info
Link to comment
Share on other sites

You cannot have the download go from the remote server through your main server. The problem is people having to get the file from your server, and if you proxy it from the other server through the main server it will look just the same - except be more expensive for you.

You need a download script on the other server as well. If you can't do that, give the user a direct URL to the file.

Link to comment
Share on other sites

I can put a download script similar to the one on the U.S. download, but without the database actions. Currently, I just give them the URL for the U.K. server via email when they report a download problem via the Contact Us page. I'm trying to avoid having to do that by giving them the choice of where to download from. The database actions would still have to take place on the U.S. server regardless of where they download from.

Link to comment
Share on other sites

@Barand - Thanks for jumping into this. Why not have the U.S. server handle the DB transactions prior to handing off to the U.K. server? If it has to be the way you describe, how would I code the DB transactions on the U.K. side to update the U.S. side DB? All that's on the U.K. side is a copy of the download folder.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.