I have this code that generates a zip with the images I keep in the download directory, these images are previously selected ...
Example for the first shipment:
I select image1, image2, image3 and image4, therefore in my download directory there will only be these 4 images and of course the zip will be created with those images.
Code for the first sent
$checked = $request->input('catalog');
foreach($checked as $check){
$path = File::where('name',$check)->select('real_path')->first();
$img = \Image::make($path->real_path);
$img->save(public_path('download'). '/'. $check);
}
$files = \File::files('download');
\Zipper::make(public_path('download/download.zip'))->add($files);
return response()->download(public_path('download/download.zip'));
Example for the second sent:
This time only select image1, image2, then I need the zip to only contain those 2 images, so it occurred to me to do this:
Delete the contents of the download directory if the download.zip exists:
if (\File::exists('download/download.zip')) {
$directory_cuts = public_path('download');
$success = \File::cleanDirectory($directory_cuts);
}
foreach($checked as $check){
$path = File::where('name',$check)->select('real_path')->first();
$img = \Image::make($path->real_path);
$img->save(public_path('download'). '/'. $check);
}
$files = \File::files('download');
\Zipper::make(public_path('download/download.zip'))->add($files);
return response()->download(public_path('download/download.zip'));
The code works in the following points:
- Remove the contents of the download directory.
- Generates the new selected images.
- Generate the zip file, with the generated images.
But it does not work in the most important one, which is to download the ZIP.
I get the following error:
The file "C:\wamp\www\Petro\public\download\download.zip" does not exist
Is there something wrong with my code?
And if there is another way to download multiple files, I would also like to know.