當前位置:首頁 » 編程語言 » php打包zip

php打包zip

發布時間: 2023-01-18 17:44:22

php網頁上打包文件生成壓縮文件zip,並彈出下載

既然你只是想學習如何打包.


那我重點就回答你這一塊,正好我剛剛用到;

$filename="./".date('YmdH').".zip";//最終生成的文件名(含路徑)
//生成文件
$zip=newZipArchive();//使用本類,linux需開啟zlib,windows需取消php_zip.dll前的注釋
if($zip->open($filename,ZIPARCHIVE::CREATE)!==TRUE){
exit('無法打開文件,或者文件創建失敗');
}

//$fileNameArr就是一個存儲文件路徑的數組比如array('/a/1.jpg,/a/2.jpg....');

foreach($fileNameArras$val){
$zip->addFile($val,basename($val));//第二個參數是放在壓縮包中的文件名稱,如果文件可能會有重復,就需要注意一下
}
$zip->close();//關閉

//下面是輸出下載;
header("Cache-Control:max-age=0");
header("Content-Description:FileTransfer");
header('Content-disposition:attachment;filename='.basename($filename));//文件名
header("Content-Type:application/zip");//zip格式的
header("Content-Transfer-Encoding:binary");//告訴瀏覽器,這是二進制文件
header('Content-Length:'.filesize($filename));//告訴瀏覽器,文件大小
@readfile($filename);//輸出文件;

㈡ thinkphp打包exe

thinkphp 打包文件,並下載

/**
* 打包下載
* 注意文件路徑都是相對路徑
* 不能使用ajax的方式
* @return [type] [description]
*/
public function allzip(){
$param = $this->request->param();

$ids = explode(",",$param['id']);

//要打包的文件
foreach ($ids as $k => $v){
$files[] =substr(db('seofile')->where('id',$v)->value('fileurl'),1);
}

$zip = new \ZipArchive;
//壓縮文件名
$filename = 'upload/file/download.zip';
//新建zip壓縮包
$zip->open($filename,\ZIPARCHIVE::OVERWRITE | \ZIPARCHIVE::CREATE);

//循環壓縮文件
foreach($files as $key => $value){

$zip->addFile($value,basename($value));

}

//打包zip
$zip->close();

header("Cache-Control:public");
header("Content-Description: File Transfer");
header("Content-disposition: attachment; filename=".basename($filename));//文件名
//header("Content-Type: application/force-download");
header("Content-Type:application/zip"); //格式為zip
header("Content-Transfer-Encoding:binary"); //這是二進制文件
header("Content-Length:".filesize($filename)); //文件大小

@readfile($filename);
// @unlink($filename);

}

㈢ 怎樣用php壓縮解壓rar,zip文件

要用PHP壓縮解壓文件,常用的方法是調用命令行去執行解壓縮操作
可以用exec()
、system()等函數調用shell命令
Linux下解壓縮命令是tar
[-cxtzjvfpPN]
文件與目錄,tar命令可以壓縮解壓.tar、.gz、.tar.gz、.tgz、.bz2、.tar.bz2、.Z、.tar.Z、.zip這些類型的文件
Linux下默認無法使用rar格式的,要另外安裝RAR
for
Linux,然後使用rar和unrar命令解壓縮rar格式的壓縮文件

㈣ php如何壓縮一個文件夾裡面所有的文件到zip文件裡面

//函數:文件壓縮
//壓縮參數:需要壓縮的文件或文件夾(文件可為數組),壓縮後的zip文件名及存放路徑,壓縮類型1:文件夾2:文件,後續操作1:壓縮後下載;2:存放在伺服器上(默認為/@Upload下)
//壓縮文件夾示例:Tozip("./","../".date("d-H-i-s").".zip",1,2);
//壓縮文件示例:
// $aaa=array("../1.txt","../2.txt");
// Tozip($aaa,"../2.zip",2);FunctionTozip($Path,
$ZipFile,
$Typ=1,
$Todo=1){//IF(!is_writeable($Path)){Exit("文件夾不可寫!");}$Path=Str_iReplace("\\","/",($Path));IF(Is_Null($Path) OrEmpty($Path) Or!IsSet($Path)){ReturnFalse;}IF(Is_Null($ZipFile) OrEmpty($ZipFile) Or!IsSet($ZipFile)){ReturnFalse;}
Include_once("inc/Class_Zip.php");$zip=NewPHPZip;IF(SubStr($Path,-1,1)=="/"){$Path=SubStr($Path,0,
StrLen($Path)-1);}
OB_end_clean();Switch($Typ){Case"1":$zip-ZipDir($Path,
$ZipFile,
$Todo);Break;Case"2":$zip-ZipFile($Path,

㈤ PHP在線解壓ZIP文件

解壓步驟:
第一步、把unzip.php或upzid.php(2選1即可)通過 FTP上傳到壓縮包所在的文件夾;
第二步、使用「域名/unzip.php或upzid.php?file=壓縮文件名稱」訪問解壓,如 www.abc.com/unzip.php?file=name.zip ;

源碼適合php環境的zip壓縮包在線解壓。

注意:解壓完成後請務必刪除站點目錄下的unzip.php和upzid.php文件,以免被其他人利用!

㈥ 請問怎麼把php文件轉化成zip文件

換一個下載工具,迅雷解析不了你的.php頁面內容,故直接給你下載.php頁面文件了
解決方案,下360瀏覽器,用自帶下載器下載

㈦ 我有個PHP程序 想將伺服器上文件打成zip壓縮包然後進行下載我能需要壓縮的文件夾的路徑 要怎麼寫

相對路徑./ 當前目錄
../上級目錄

熱點內容
人事管理系統的資料庫設計 發布:2025-07-17 11:54:27 瀏覽:229
統治戰場kk腳本 發布:2025-07-17 11:53:45 瀏覽:239
安卓的數據線介面有什麼顏色 發布:2025-07-17 11:53:03 瀏覽:871
塑料壓縮器 發布:2025-07-17 11:52:15 瀏覽:724
手機百度雲如何秒上傳 發布:2025-07-17 11:46:27 瀏覽:612
交易貓買腳本靠譜嗎 發布:2025-07-17 11:32:27 瀏覽:520
伺服器系統盤一般做什麼陣列 發布:2025-07-17 11:16:05 瀏覽:363
如何用c語音實現放射密碼 發布:2025-07-17 11:13:03 瀏覽:735
lol腳本2017 發布:2025-07-17 10:52:18 瀏覽:827
編譯條件有哪些 發布:2025-07-17 10:42:51 瀏覽:334