I have two large files that I want to make available for users to download. When trying to download from my web host, the download never starts and I get a "504 Gateway Timeout". How would I revise my code to download from a file sharing site? I tried the following code but get a "This page isn’t workingfoxclone is currently unable to handle this request."

Appreciate any help you can provide.

<?php

function mydloader($l_filename=NULL) {

    $php_scripts = '../../php/';
    require $php_scripts . 'PDO_Connection_Select.php';
    require $php_scripts . 'GetUserIpAddr.php';

    if( isset( $l_filename ) ) { 

       if substr($l_filename, 0, 10)=='foxclone_s' {
            $url_path = 'https://www.mediafire.com/file/tyqr4tzthiftuy1/foxclone_std-50-06.iso/file' }
       elseif substr($l_filename, 0, 10)=='foxclone_e' {
          $url_path = 'https://www.mediafire.com/file/xnovs5ltdj2z5wr/foxclone_edge-50-07.iso/file'  }
      else

              header('Content-Type: application/octet-stream');
              header("Content-Transfer-Encoding: Binary"); 
              header("Content-disposition: attachment"); 
              header('Pragma: no-cache');
              header('Expires: 0');       
              readfile($l_filename);
    }


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


        $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);

        $ext = pathinfo($l_filename, PATHINFO_EXTENSION);
        $stmt = $pdo->prepare("INSERT INTO download (address, filename, ip_address, lookup_id) VALUES (?, ?, inet_aton('$ip'), ?)");
        $stmt->execute([$ip, $ext, $ref ]) ; 

       }

    else {
        echo "isset failed";
        }  
}
mydloader($_GET["f"]);

Dani AI

Generated

Serving large downloads through a PHP script is often what triggers host limits (timeouts, memory, proxy limits). reported the issue was resolved after host-side changes, which is common — hosts will throttle or kill long-running PHP processes. also pointed out that using third-party file hosts introduces access and policy complications. Consider whether the server should actually stream the bytes, or only authenticate and hand off the transfer.

The most efficient pattern is to have PHP do authentication/logging and then hand the file delivery to the web server. On Apache use X-Sendfile; on Nginx use X-Accel-Redirect. Example headers PHP would emit after doing any DB logging or permission checks:

<?php
// after auth and logging:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="large.iso"');
header('X-Sendfile: /full/path/to/large.iso'); // Apache
exit;
?>
<?php
// Nginx variant (internal location mapping required)
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="large.iso"');
header('X-Accel-Redirect: /protected/internal/large.iso');
exit;
?>

If the files sit on cloud/object storage, the best practice is to offload entirely: generate a short-lived signed URL (S3/Cloud Storage) or serve via a CDN and redirect the client there. That keeps your web host out of the data path and avoids gateway timeouts or bandwidth limits.

If none of the above are possible and PHP must stream, do it in small chunks, disable output buffering, call set_time_limit(0), and write a short DB log before streaming (avoid keeping DB transactions open during the transfer). Also verify any third-party host terms before proxying or hiding links — many providers require their UI or an API and disallow hotlinking.

Recommended Answers

All 4 Replies

All the sites I've seen use Mediafire supply a link to the file and we end up on the Mediafire site to complete the download. Why this is, is likely because Mediafire is ad supported and more. I'm guessing you want to bypass all that and hide the URL of the actual download. But I could be wrong.

Also, when I tried the URL from line 14 Mediafire coughed up errors. Such as "This file is currently set to private." so not only do you have to research if what you are asking is possible but would have to login to Mediafire via PHP or such.

In other words, Mediafire for what I'm guessing you are trying to do looks like a dead end. But if you want to present a page with the download link, Mediafire is fine here.

- Your assumption near the end of your first paragraph is correct. I want to hide the URL of the actual download

Given you are creating your own up/downloader all I can offer is that Mediafire looks like a dead end as well, reasons.

I see from your other discussion you were trying the single line of PHP to send the file and that fails for the reasons Dani and maybe others noted.

So what to do but write your own up/downloader. It will have to read and send in chunks like we see at https://www.tutorialspoint.com/how-to-download-large-files-through-php-script Sorry but I can't write this for you.

My web host made some adjustments to my account. The downloads of the large files now works correctly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.