0

I have a zip folder that I want to place into the root of my application. The zip folder and contents looks like this;

documents.zip
  - docs/
    - index.html
    - test.txt

Using the following code;

$zip = new ZipArchive;

$zip->open( $package, ZIPARCHIVE::CREATE );

$zip->extractTo( ROOTPATH );

The zip folder is unzipped and ends up looking like this;

- docs/
  - index.html
  - test.txt

However I'd like to place the contents of the docs folder in the actual environment root. ROOTPATH (the env root, from above) evaluates to app/public/ so the zip folder contents is currently unzipped to app/public/docs/.

How can I move the contents with ZipArchive into the root?

  • You _never_ want to enable `php` to write into the file system location that is served by your http server. – arkascha Nov 14 '18 at 22:02
  • The PHP implementation doesn't seem to have the "junk paths" option, but you can do this from the shell with `unzip -j`. – Alex Howansky Nov 14 '18 at 22:06
  • You can check this post https://stackoverflow.com/questions/6682491/extract-files-in-a-zip-to-root-of-a-folder – Dan D. Nov 14 '18 at 22:13
  • http://php.net/manual/en/ziparchive.extractto.php vuser note 1 seems to be what you are asking –  Nov 14 '18 at 22:13

0 Answers0