【发布时间】: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 代码是什么?