2

I am using Zipper to extract uploaded zip file and delete the file after extract. So I upload and extract like this:

$f = $request['file']->move(public_path($directory), $fullFileName);
\Zipper::make($f)->extractTo(public_path($directory) . $fileName);

and it works great. I've tried to delete the file using these ways.

1 - Storage::disk('products')->delete($fullFileName);
2 - File::delete(public_path($directory) . $fullFileName);
3 - $del = unlink(public_path($directory) . $fullFileName);

but in all actions get resource temporarily unavailable error. I found this error is because of the zipper (simple files and directories works).

so my question is, How can I delete upload zip file after extract, using a zipper?

Any idea would be great. thanks in advance.

babar junaid
  • 99
  • 1
  • 12
Alireza Saremi
  • 401
  • 1
  • 7
  • 13

2 Answers2

4

You need to call $zipper->close(); after you extract it, so if you do something like this it should work:

$zipper = new \Chumper\Zipper\Zipper;
$zipper->make($f)->extractTo(public_path($directory) . $fileName);
$zipper->close();
unlink(public_path($directory) . $fullFileName);

If you do not close the zipper it will not write the result to the disk and keep the original file locked. See the documentation.

Sven Hakvoort
  • 3,543
  • 2
  • 17
  • 34
2
$zip = new Zipper;
$zip->make($pathZipFile)->extractTo($destinationPath);
$zip->close(); // important
unlink($pathZipFile); // delete Zip file after 
Waad Mawlood
  • 727
  • 6
  • 10