Cannot download the file from the server?

Use this module: https://github.com/Chumper/Zipper
Method:
public function getDownloadAllPassport($passports)
{
 $passports = explode(',', $passports);
 $name = uniqid();
 foreach ($passports as $passport) {
 $user_name = VisaOrder::findOrFail($passport)->name;
 if (Upload::getFiles('passport', $user_name)) {
 File::copyDirectory("upload/passport/$user_name", "upload/zip/$name/$user_name");
}
}
Zipper::make("upload/zip/$name/passport.zip")->add(glob("upload/zip/$name"));
 return response()->download(public_path("upload/zip/$name/passport.zip"));
 }

The method works almost as it should, ziguet and copies where necessary. But in the end when you need to give the file gives errors like this:
FileNotFoundException in File.php line 37:
The file "/home/dragger/MyProjects/site.local/public/upload/zip/5824f3b11b986/passport.zip" does not exist

Decided to experiment sicometal of all the code in the method except the return statement :
public function getDownloadAllPassport($passports)
{
// $passports = explode(',', $passports);
// $name = uniqid();
// foreach ($passports as $passport) {
// $user_name = VisaOrder::findOrFail($passport)->name;
// if (Upload::getFiles('passport', $user_name)) {
// File::copyDirectory("upload/passport/$user_name", "upload/zip/$name/$user_name");
// }
// }
// Zipper::make("upload/zip/$name/passport.zip")->add(glob("upload/zip/$name"));
 return response()->download(public_path("upload/zip/5824f3b11b986/passport.zip"));
 }

As here I have is downloading the file. I don't know why he the first time will be invisible.
July 2nd 19 at 17:51
1 answer
July 2nd 19 at 17:53
Solution
Try another library, without any extra fuss with the file system.
composer require nelexa/zip

public function getDownloadAllPassport($passports)
{
 $passports = explode(',', $passports);
 $name = uniqid();
 $zipFile = \PhpZip\ZipOutputFile::create();
 foreach ($passports as $passport) {
 $user_name = VisaOrder::findOrFail($passport)->name;
 if (Upload::getFiles('passport', $user_name)) {
 $recursive = true;
 $toZipPath = $name . '/';
 $zipFile->addDir("upload/passport/$user_name", $recursive, $toZipPath);
}
}
$zipFile->outputAsAttachment('passport.zip');
}
Thank you!!! very handy!!! - brook.Dare commented on July 2nd 19 at 17:56

Find more questions by tags LaravelPHP