Cakephp 3 Download Large Files

Asked

Viewed 20 times

0

I have the following problem. My Cakephp 3 application stores some BIG files (200mbs), uploaded via FTP. These files are in a folder outside of my project.

When you click on the download link, it starts to be sent to the user, but the site navigation is frozen, not allowing you to browse between other screens.

// no Controller
public function download($id=null) {
   // ... Acessa o registro para capturar o caminho do arquivocakpehp
   $filePath = '/caminho/do/arquivo.xxx';

   return $this->response
                    ->withHeader('Content-Type', 'application/zip')
                    ->withHeader('Content-Disposition', 'attachment;')
                    ->withHeader('Cache-Control', 'max-age=0')
                    ->withHeader('Cache-Control', 'max-age=1')
                    ->withHeader('Expires', 'Mon, 26 Jul 2500 05:00:00 GMT')
                    ->withHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' PDT')
                    ->withHeader('Cache-Control', 'cache, must-revalidate')
                    ->withHeader('Pragma', 'public')
                    ->withFile($filePath, ['download' => true]);

}

What am I doing wrong? That was one of the ways I tested.

  • It gets frozen because you’re probably using PHP SESSION, even if it’s internally in FW, before the return try to run session_write_close();. I don’t know how it works in cakephp, maybe this screen of yours wouldn’t even need a session.

  • Show, solved my problem. Thank you very much.

  • For nothing Felipe, I closed as dup, because the other answer I asked in the other question details all about this, but keep your question, that it will serve as reference for the answer to future visitors ;)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.