0

I have a script setup so users can download files via a php script (one time use link) however when the file size reaches 1GB it fails to download any further.

It stops exactly at 1GB

Is there some setting in php.ini that would allow me to adjust it to go beyound 1GB? I have tried changing most of the settings below but i dont see anything that would relate to a 1GB file size ...

Example: www.url.com/file.php?download=filename.zip (uses the below php code)

<?php
 $DownloadableFilesDirectory = "/dl/secret";
 $FileRenamePrependCharacters = "odroid_";

 if( ! empty($FileRenamePrependCharacters) ) { $FileRenamePrependCharacters = 
 ltrim($FileRenamePrependCharacters); }
 $DownloadableFilesDirectory = 
 preg_replace('/^\/*/','/',$DownloadableFilesDirectory);
 $DownloadableFilesDirectory = 
 preg_replace('/\/*$/','',$DownloadableFilesDirectory);
 $Directory = $_SERVER['DOCUMENT_ROOT'].$DownloadableFilesDirectory;
 if( empty($_GET['download']) ) { exit; }
 if( empty($_GET['savefile']) ) { $_GET['savefile'] = $_GET['download']; }
 $Dfile = $Directory.'/'.$_GET['download'];
 $size = filesize($Dfile);
 if( ! $size )
{
    echo '<p><b>The download file is empty or was not located.</b></p>';
    exit;
 }
 $ctype = 'application/octet-stream';
 header('Cache-control: private');
 header("Content-Type: $ctype");
 header('Content-Disposition: attachment; filename="'.$_GET['savefile'].'"');
 header('Content-Transfer-Encoding: binary');
 header("Content-Length: $size");
 @readfile($Dfile);
 if( empty($FileRenamePrependCharacters) ) { unlink($Dfile); }
 else
 {
    $pieces = explode('/',$Dfile);
    $pieces[count($pieces)-1] = $FileRenamePrependCharacters . 
 $pieces[count($pieces)-1];
    rename($Dfile,implode('/',$pieces));
  }
 exit;
 ?>

Php Settings

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

1 Answers1

0

unless you're getting errors like PHP Fatal error: Maximum execution time of ??? seconds exceeded in foo.php on line ? in the error log, or being stupid and saving all the downloaded contents in ram and get errors like PHP Fatal error: Allowed memory size of ??? bytes exhausted (tried to allocate ??? bytes) in foo.php on line ? in the error log (and you're not doing that, going by the code you posted), this is not a PHP problem, it's a problem with the web server you're using. (nginx? apache? lighthttpd? microsoft's IIS? some proxy? some load balancer ala Cloudflare?), start your investigation there.

hanshenrik
  • 19,904
  • 4
  • 43
  • 89
  • 1
    the readfile() function doesn't load the entire file in memory. And a lack of experience or knowledge is not a proof of stupidity :/ – Jordan Breton Aug 02 '18 at 13:25
  • I just looked at php.ini settings it says Server API LiteSpeed V7.1 PHP Version 7.0.3 – Douglas Littlefield Aug 02 '18 at 13:30
  • 1
    @DouglasLittlefield then check the LiteSpeed configuration / error logs, the problem is almost certainly with LiteSpeed – hanshenrik Aug 02 '18 at 13:36
  • @DouglasLittlefield and what configuration is it using? – hanshenrik Aug 02 '18 at 13:55
  • would it do any harm if i post the link to view the php.ini settings? – Douglas Littlefield Aug 02 '18 at 13:58
  • @DouglasLittlefield in the vast majority of cases, no. for example, here is 1 of my servers: http://ratma.net/phpinfo.php - however, if you use the `mysql.default_user` / `mysql.default_password` / `mysqli.default_pw` php.ini configuration options, then it's a problem. check for these options before publishing the ini. (but actually using those settings is a terrible design choice anyway..) – hanshenrik Aug 02 '18 at 15:46