簡體   English   中英

PHP-從一個文件創建一個zip文件

[英]PHP - Created a zip file from a single file

一切正常,包括所有密碼保護部分,但無法解決上一期問題。

要求是在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()方法返回的整個路徑?

似乎您需要-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()來覆蓋存檔中的文件名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM