Im using Laravel 5.2 and Zipper to create a zip archive on the fly and download it by user. I think this problem is not strictly related to Laravel or Zipper. Steps:
- User click the download_all link.
- The first php script to create an archive.
- Next, the same script, click the created file to force the user to load.
Everything sounds fine, but I have a strange behavior that after creating a zip archive (point 2) php / server does not see this newly created file . Both filesize and file_exists in $ filePath return false, but the file exists. I can not read the file why?
When I redirect the user to $ filePath (instead of reading it and clicking to download), everything is fine and the user receives the file. But why can't I access the newly created file during the "script lifetime"? $ paths are correct. Tested on Windows 7 and Unix.
Any idea?
the code:
public function downloadAll($id)
{
$sourceFilesDir = 'upload/source/' . $id;
$zipPath = 'upload/source-zip/' . date('Y-m-d-H-i-s') . '.zip';
Zipper::make($zipPath)->add($sourceFilesDir);
$fullPath = public_path($zipPath);
$headers = [
'Content-Type: application/zip',
'Content-Transfer-Encoding: Binary',
'Content-Length: ' . filesize($fullPath),
];
return response()->download($fullPath, basename($zipPath), $headers);
}
source
share