Skip to content

Why disallow to add specific files within a folder? #66

@serious-angel

Description

@serious-angel

Dear Developers,

Thank you for the project!

Currently, if we want to keep a directory inside a ZIP file, the library would not support it, where it provides two main options:

  1. Add a whole directory only with all the files inside;
  2. Add a file to the root of the ZIP.

As we may see, the private function addItem has the parameter base:

laravel-zip/src/Zip.php

Lines 613 to 616 in ddecbf6

} else if (is_file($real_file)) {
$file_target = is_null($base) ? $real_name : $base . $real_name;
$add_file = $this->zip_archive->addFile($real_file, $file_target);


Yet, the parameter is unset in all the callers, except the directory iterator, and therefore an explicit file addition always matches the "basename". That, in turn, sets all the ZIP entry-names to the root of the ZIP.

What if there's a single file (in a source directory of multiple files) to be added into a specific folder inside a ZIP file (e.g. misc/file.txt)?

The current solution is to get the native ZipArchive object and call the PHP built-in methods, but... why the library then in the first place?

Is that the intended limitation?


Meanwhile, I am sorry, but why add/leave the so custom mode as ZANYSOFT in the so popularized library, including Laravel News?

Best and kind regards ✨

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions