PHP - 从单个文件创建一个zip文件

时间:2018-04-17 14:59:06

标签: php laravel zip

让一切正常运行,包括所有密码保护部分,但无法完成最后一期。

要求是在Laravel应用程序上,CSV是作为受密码保护的zip创建和下载的。

为此,我有一个在本地存储CSV的类,然后是一个调用以下内容的方法:

echo system('zip -P ' .$this->password. ' ' .$this->getZipStoragePath(). ' ' .storage_path('app/').$this->getFilePath());

这个“有效”,因为它创建了一个受密码保护的zip文件。但是当提取时,我的机器有一个文件夹结构,直到指向找到这个文件。

因此,提取这个创建的zip给我一个目录:

Users > Craig > Apps > Project Name > Storage > app > temp > then the file here.

有没有办法可以使用相同的zip系统方法,但是它只压缩文件,而不是像storage_path()方法返回的整个路径?

1 个答案:

答案 0 :(得分:1)

您似乎想要-j标志:

-j
--junk-paths
     Store just the name of a saved file (junk the path), and do
     not store directory names. By default, zip will store the
     full path (relative to the current directory).

另请注意,您可以使用本机PHP Zip支持,并使用可选的第二个参数调用addFile()来覆盖存档中的文件名。

相关问题