Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy don't large files download easily in Laravel?
    text
    copied!<p>My file (126 MB size, .exe) is giving me issues.</p> <p>I'm using the standard laravel download method.</p> <p>I tried increasing the memory but it still either says I have run out of memory, or I download a 0 KB size file.</p> <p>The documentation doesn't mention anything about large file sizes.</p> <p>My code is </p> <pre><code>ini_set("memory_limit","-1"); // Trying to see if this works return Response::download($full_path); </code></pre> <p><strong>Anything I am doing wrong?</strong></p> <p>-- Edit --</p> <p>Going on Phill Sparks comment, this is what I have and <strong>it works</strong>. It's a a combinations of Phill's plus some from php.net. Not sure if there is anything in there missing?</p> <pre><code>public static function big_download($path, $name = null, array $headers = array()) { if (is_null($name)) $name = basename($path); // Prepare the headers $headers = array_merge(array( 'Content-Description' =&gt; 'File Transfer', 'Content-Type' =&gt; File::mime(File::extension($path)), 'Content-Transfer-Encoding' =&gt; 'binary', 'Expires' =&gt; 0, 'Cache-Control' =&gt; 'must-revalidate, post-check=0, pre-check=0', 'Pragma' =&gt; 'public', 'Content-Length' =&gt; File::size($path), ), $headers); $response = new Response('', 200, $headers); $response-&gt;header('Content-Disposition', $response-&gt;disposition($name)); // If there's a session we should save it now if (Config::get('session.driver') !== '') { Session::save(); } // Below is from http://uk1.php.net/manual/en/function.fpassthru.php comments session_write_close(); ob_end_clean(); $response-&gt;send_headers(); if ($file = fopen($path, 'rb')) { while(!feof($file) and (connection_status()==0)) { print(fread($file, 1024*8)); flush(); } fclose($file); } // Finish off, like Laravel would Event::fire('laravel.done', array($response)); $response-&gt;foundation-&gt;finish(); exit; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload