PHP and ZIP creation: standard zip options can be used

Does anybod know how PHP ZIP functions can be used to apply standard zip " options " when creating zip files. So far, all my searches have not found anything.

In particular, I am interested in using the " -ll " and " -l " options, so I can offer either WIN or NIX versions of files on a lightning-fast basis (cgi, php and text files, etc.) from the website nix. The content will be zipped on the fly with some files edited as added for each particular client.

I am aware of creating and using back-ticked (Perl) or passthru (.) (Php) command line commands, but I hope there is a trick for this using pure php, i.e. ZipArchive ().

Sincerely.

+4
source share
2 answers

You can go back to shell_exec and just make a zip using your own system, then you can pass -ll or -l as you wish. http://php.net/manual/function.shell-exec.php

0
source

I think str_replace () is pretty obvious. But this memory intensity is for large files.

I will not show all the code, but php uses a rarely used function, where you can apply filters to streams, and filters can be specified as part of the file URL. This makes it easy to connect to certain file system operations that would otherwise prevent you from easily customizing the behavior.

Once you define a filter with stream_filter_register (), you should be able to pass the file URL, for example php://filter/string.to_unix_line_endings/resource=/path/to/the/file.txt , to ZipArchive::addFile()

ultimately, you could just create a temporary file and copy the contents of the file into it in pieces, str_replacing as you go through, and then pass the name tempfile to the ZipArchive::addFile() method. And that would be much easier to code.

0
source

Source: https://habr.com/ru/post/1412834/


All Articles