Chumper / Zipper

This is a simple Wrapper around the ZipArchive methods with some handy functions
Apache License 2.0
845 stars 268 forks source link

Downloading the zip #76

Open Frasaccordi opened 8 years ago

Frasaccordi commented 8 years ago

Hi @Chumper

Thanks for make the zipper. i have an error when try to downloading the zip after create new zip

i have this for make zip and download it. after that, i delete it in the server

$zipper->make('export/'.$fileName.'.zip')->add($files);
return Response::download(public_path('export/'.$fileName.'.zip'))->deleteFileAfterSend(true);

i have error that the file is doesnt exist. but when i click back and try to download again, its work well. any solution? thanks!

lucasolinas commented 8 years ago

@sadalsuud

Hi, you need chain function ->close() for wait to ready the zip file. In my case: Zipper::make(public_path() . '/quibdo.zip')->add($files)->close(); It work! :D

zhenyongchan commented 7 years ago

Hi all @lucasolinas .

Thanks for the above solution. But I also need to download the zip file into the user local PC as well since the above code only download the zip file into server. Is there any code have to add in order to do so.

nicckk3 commented 6 years ago

I use below code and it's work for me. $product = Product::find($id); if ($product->brochure_array != null) { $product->brochure_array = unserialize($product->brochure_array); //dd($product->brochure_array); if (!is_dir('zipFiles')) { mkdir('zipFiles'); } if (!isdir('zipFiles/brochure')) { mkdir('zipFiles/brochure'); } $brochureName='zipFiles/brochure/brochure'.time().'.zip'; Zipper::make($brochureName)->add([$product->brochure_array])->close();

        return response()
            ->download(public_path($brochureName));

    } else {
        return redirect()->back()->with('error', "Opps! Invalid request");
    }