Skip to content
Advertisement

Ziparchive always includes parent directory

I am trying to zip all files and folder within a folder The structure looks like so:

JavaScript

When I run the zip script I want the zip to be 3.zip with all the folders and files in the next level However I always end up with:

JavaScript

Where I want:

JavaScript

The code works on my Linux servers, but on IIS and windows I get the additional level.

This is my code:

JavaScript

I have tried to exclude the file from the loop by saying ‘if $name == $request->course_id’ skip this but that doesnt work because I dont see $name ever being just the folder name.

Advertisement

Answer

This will extracts the filename from the path.
$zip->addFile($file,basename($file));

And another guess would be that you need to include course_id here also:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement