【问题标题】:PHP File Downloads all stop exactly at 1GBPHP 文件下载全部停止在 1GB
【发布时间】:2018-08-02 13:03:07
【问题描述】:

我有一个脚本设置,因此用户可以通过 php 脚本(一次性使用链接)下载文件,但是当文件大小达到 1GB 时,它无法进一步下载。

它恰好在 1GB 处停止

php.ini 中是否有一些设置可以让我将其调整为超过 1GB?我已尝试更改以下大部分设置,但我没有看到任何与 1GB 文件大小相关的内容...

示例:www.url.com/file.php?download=filename.zip(使用以下 php 代码)

<?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;
 ?>

【问题讨论】:

  • 您如何准确地提供文件?
  • 你的服务器是什么? Apache 还是 Nginx? Apache 中有限制下载的设置。
  • www.url.com/file.php?download=filename.zip www.url.com/download.php?key=key5b6301db49f094.90762935&i=0
  • 让我换个说法:您用来启用该下载的 PHP 代码是什么?

标签: php file download


【解决方案1】:

除非您在错误日志中遇到 PHP Fatal error: Maximum execution time of ??? seconds exceeded in foo.php on line ? 之类的错误,或者您很愚蠢并将所有下载的内容保存在 ram 中并在错误日志中遇到 PHP Fatal error: Allowed memory size of ??? bytes exhausted (tried to allocate ??? bytes) in foo.php on line ? 之类的错误(而您没有这样做,继续根据您发布的代码),这不是 PHP 问题,而是您使用的 Web 服务器的问题。 (nginx?apache?lighthttpd?微软的 IIS?一些代理?一些负载平衡器 ala Cloudflare?),开始你的调查。

【讨论】:

  • readfile() 函数不会将整个文件加载到内存中。缺乏经验或知识并不是愚蠢的证明:/
  • 我刚刚查看了 php.ini 设置,上面写着 Server API LiteSpeed V7.1 PHP Version 7.0.3
  • @DouglasLittlefield 然后检查 LiteSpeed 配置/错误日志,几乎可以肯定问题出在 LiteSpeed
  • @DouglasLittlefield 以及它使用什么配置?
  • 如果我发布链接来查看 php.ini 设置会不会有什么坏处?
猜你喜欢
  • 1970-01-01
  • 2019-08-20
  • 1970-01-01
  • 2021-10-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-02
  • 1970-01-01
相关资源
最近更新 更多