foxclone Posted February 11, 2021 Share Posted February 11, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/ Share on other sites More sharing options...
gw1500se Posted February 11, 2021 Share Posted February 11, 2021 I would do it with JQuery get. Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/#findComment-1584383 Share on other sites More sharing options...
requinix Posted February 11, 2021 Share Posted February 11, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/#findComment-1584385 Share on other sites More sharing options...
foxclone Posted February 11, 2021 Author Share Posted February 11, 2021 @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. Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/#findComment-1584389 Share on other sites More sharing options...
requinix Posted February 11, 2021 Share Posted February 11, 2021 Thing is, the code you've shown does some database stuff. That's not the place where the download happens, nor the place where the user clicks a link to get the download. Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/#findComment-1584390 Share on other sites More sharing options...
foxclone Posted February 11, 2021 Author Share Posted February 11, 2021 (edited) @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 February 11, 2021 by foxclone added info Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/#findComment-1584392 Share on other sites More sharing options...
requinix Posted February 11, 2021 Share Posted February 11, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/#findComment-1584393 Share on other sites More sharing options...
foxclone Posted February 11, 2021 Author Share Posted February 11, 2021 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. Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/#findComment-1584395 Share on other sites More sharing options...
Solution Barand Posted February 11, 2021 Solution Share Posted February 11, 2021 UK Script - downloads from local UK file server and DB connection is to (remote) US DB server US Script - downloads from local US file server and DB connection is to (local) US DB server. Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/#findComment-1584396 Share on other sites More sharing options...
foxclone Posted February 11, 2021 Author Share Posted February 11, 2021 @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. Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/#findComment-1584397 Share on other sites More sharing options...
Barand Posted February 12, 2021 Share Posted February 12, 2021 My way the two scripts would be identical except the US one connects locally to the mysql server and the UK one connects remotely. (If the US DB server is not local to the US page then both would connect using the DB server's IP address) Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/#findComment-1584409 Share on other sites More sharing options...
foxclone Posted February 13, 2021 Author Share Posted February 13, 2021 @Barand - Thanks for putting me on the right track, it's fixed. Quote Link to comment https://forums.phpfreaks.com/topic/312131-need-help-php-download-from-remote-url/#findComment-1584431 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.