Answer the question
In order to leave comments, you need to log in
Unable to download a file from the server?
I 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"));
}
FileNotFoundException in File.php line 37:
The file "/home/dragger/MyProjects/site.local/public/upload/zip/5824f3b11b986/passport.zip" does not exist
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"));
}
Answer the question
In order to leave comments, you need to log in
Try another library, without too much fiddling with the file system.
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');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question