Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter force_下载在大型Zip文件上失败_Php_Codeigniter_Zip - Fatal编程技术网

Php Codeigniter force_下载在大型Zip文件上失败

Php Codeigniter force_下载在大型Zip文件上失败,php,codeigniter,zip,Php,Codeigniter,Zip,使用force_download下载zip文件时,我的代码适用于268Mb的zip文件(31个MP3文件),但不适用于287Mb的zip文件(32个MP3文件),不同之处是在zip中添加了1个额外的MP3文件。下载尝试开始,看起来好像它一直在重复多次,并显示为失败,Chrome显示zip文件不完整。Windows报告只有61Kb的zip文件在尝试打开时无效 zip文件被创建,MP3文件被另一个代码区添加到其中 我已经将内存限制增加到了1024M,但也没什么不同 下面是我想要的代码: $this-

使用
force_download
下载zip文件时,我的代码适用于268Mb的zip文件(31个MP3文件),但不适用于287Mb的zip文件(32个MP3文件),不同之处是在zip中添加了1个额外的MP3文件。下载尝试开始,看起来好像它一直在重复多次,并显示为失败,Chrome显示zip文件不完整。Windows报告只有61Kb的zip文件在尝试打开时无效

zip文件被创建,MP3文件被另一个代码区添加到其中

我已经将
内存限制增加到了
1024M
,但也没什么不同

下面是我想要的代码:

$this->load->helper("download");
$lastbasket = "uniquefilename.zip";
$zipdlpath = base_url()."uploads/zipped/".$lastbasket;
$fileContent = file_get_contents($zipdlpath);
force_download($lastbasket, $fileContent);
我还尝试使用以下代码:

$this->load->helper("download");
$lastbasket = "uniquefilename.zip";
$zipdlpath = FCPATH."uploads/zipped/".$lastbasket;
force_download($zipdlpath, NULL);
提供到zip文件的直接链接可以很好地工作(因此我知道问题不在于zip文件本身),但是控制器中的force_download功能似乎对较大的文件有问题,或者我缺少的某个设置是否以某种方式强制了限制

PHP 7.1.33
CodeIgniter 3.1.9

尝试通过添加以下代码来增加内存限制:

ini_set('memory_limit','1024M');

我已经尝试了以下自定义下载帮助程序,希望它对您有用


参考链接-

增加内存限制并使用fopen、fread

试试这个

$this->load->helper("download");
$lastbasket = "uniquefilename.zip";
$zipdlpath = FCPATH."uploads/zipped/".$lastbasket;
force_download($zipdlpath, NULL);
if (is_file($zipdlpath))
{
    $chunkSize = 1024 * 1024;
    $handle = fopen($zipdlpath, 'rb');
    while (!feof($handle))
    {
        $buffer = fread($handle, $chunkSize);
        echo $buffer;
        ob_flush();
        flush();
    }
    fclose($handle);
    exit;
}

max_execution_time设置为600秒,下载在10秒内失败。post_max_size设置为500M,但代码没有发布任何内容,因此这与问题无关。