unzipper
unzipper copied to clipboard
Feature: exclude leading directory when extracting
This pull request aims to add a new feature to unzipper. If an archive to be extracted only contains one single directory in its root, unzipper can now choose to only extract the content of this single directory and not include the directory itself in the extraction.
The feature is controlled by a checkbox added to the HTML.
I got this idea when trying to deploy WordPress on a new website. After extracting the zip file downloaded from wordpress.org I got a wordpress/ directory in my website root instead of the WordPress files and folders, which is not what I intended.
I tried many solutions to this problem and finally decided on the following:
- extract archive to a newly created empty temporary directory (tempdir) and move all files and folder from the tempdir to the real destination.
- if the tempdir only contains one single directory, move the content of said directory instead of the tempdir content.
It may seem like a better idea to extract each file from an archive directly to the destination folder, thereby not needing a tmpdir. But the only way I found to do this was by iterating over the archive files and using copy("zip://archive.zip#path/to/file.txt")
. And this solution has serious performance problems with larger archives. Archives that can normally be extracted will instead be cancelled by the PHP max_execution_time.
The implemented solution is also easy to incorporate in any future additions to supported archive formats.
Feedback is welcome.
Should I maybe wait a little more before receiving a response on this? Or is the project dead?
Any ideas or comments on this? I really like this project, and I think it would be awesome if this feature was added.