Why don't large files download easily in Laravel?

前端 未结 5 1746
野趣味
野趣味 2020-12-09 06:40

My file (126 MB size, .exe) is giving me issues.

I\'m using the standard laravel download method.

I tried increasing the memory but it still either says I ha

5条回答
  •  伪装坚强ぢ
    2020-12-09 07:01

    I'm using the readfile_chunked() custom method as stated in php.net here. For Laravel 3, I've extended the response method like this:

    Add this file as applications/libraries/response.php

    Then comment out this line in application/config/application.php:

    'Response'      => 'Laravel\\Response',
    

    Example code:

    //return Response::download(Config::get('myconfig.files_folder').$file->upload, $file->title);
    
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.$file->title);
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . File::size(Config::get('myconfig.files_folder').$file->upload));
    ob_clean();
    flush();
    Response::readfile_chunked(Config::get('myconfig.files_folder').$file->upload);
    exit;
    

    Works great so far.

提交回复
热议问题