導航:首頁 > 編程語言 > php創建zip

php創建zip

發布時間:2022-10-03 07:41:23

A. php如何開啟ZIP模塊

第一步、找到php.ini文件

第二部、用記事本打開

第三步、使用ctrl鍵+F鍵搜索;extension=php_zip.dll

第四步、去除extension前面的分號「;」,如extension=php_zip.dll

第五步、保存重啟Apache或其他伺服器。

如圖:

B. 如何安裝 php 的zip模塊

zip 是php的一個擴展,用於支持zip文件壓縮解壓
按照下面的步驟配置:
1. 用記事本編輯你的 php.ini 文件,搜索 zip.dll 然後把這一行前面的 ; (分號)去掉,保存 php.ini 注意,這一行的上面應該有很多諸如 ;php_***.dll 的,否則搜索的位置不正確,再次搜索
2. 重新啟動你的 WEB 伺服器。IIS直接在 開始 運行 裡面輸入 iisreset, Apache 通過管理器先停止再啟動即可

C. 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);//輸出文件;

D. 如何用PHP創建一個加密的zip壓縮文件

/* creates a compressed zip file */function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && !$overwrite) { return false; } //vars $valid_files = array(); //if files were passed in... if(is_array($files)) { //cycle through each file foreach($files as $file) { //make sure the file exists if(file_exists($file)) { $valid_files[] = $file; } } } //if we have good files... if(count($valid_files)) { //create the archive $zip = new ZipArchive(); if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } //add the files foreach($valid_files as $file) { $zip->addFile($file,$file); } //debug //echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status; //close the zip -- done! $zip->close(); //check to make sure the file exists return file_exists($destination); } else { return false; }}

E. PHP-php生成zip壓縮文件如何給該文件加解壓縮密碼

<?php
//需開啟配置php_zip.dll
//phpinfo();
header("Content-type:text/html;charset=utf-8");
functionget_zip_originalsize($filename,$path){
//先判斷待解壓的文件是否存在
if(!file_exists($filename)){
die("文件$filename不存在!");
}
$starttime=explode('',microtime());//解壓開始的時間

//將文件名和路徑轉成windows系統默認的gb2312編碼,否則將會讀取不到
$filename=iconv("utf-8","gb2312",$filename);
$path=iconv("utf-8","gb2312",$path);
//打開壓縮包
$resource=zip_open($filename);
$i=1;
//遍歷讀取壓縮包裡面的一個個文件
while($dir_resource=zip_read($resource)){
//如果能打開則繼續
if(zip_entry_open($resource,$dir_resource)){
//獲取當前項目的名稱,即壓縮包裡面當前對應的文件名
$file_name=$path.zip_entry_name($dir_resource);
//以最後一個「/」分割,再用字元串截取出路徑部分
$file_path=substr($file_name,0,strrpos($file_name,"/"));
//如果路徑不存在,則創建一個目錄,true表示可以創建多級目錄
if(!is_dir($file_path)){
mkdir($file_path,0777,true);
}
//如果不是目錄,則寫入文件
if(!is_dir($file_name)){
//讀取這個文件
$file_size=zip_entry_filesize($dir_resource);
//最大讀取6M,如果文件過大,跳過解壓,繼續下一個
if($file_size<(1024*1024*6)){
$file_content=zip_entry_read($dir_resource,$file_size);
file_put_contents($file_name,$file_content);
}else{
echo"<p>".$i++."此文件已被跳過,原因:文件過大,->".iconv("gb2312","utf-8",$file_name)."</p>";
}
}
//關閉當前
zip_entry_close($dir_resource);
}
}
//關閉壓縮包
zip_close($resource);
$endtime=explode('',microtime());//解壓結束的時間
$thistime=$endtime[0]+$endtime[1]-($starttime[0]+$starttime[1]);
$thistime=round($thistime,3);//保留3為小數
echo"<p>解壓完畢!,本次解壓花費:$thistime秒。</p>";
}
$size=get_zip_originalsize('20131101.zip','temp/');
?>

F. 如何在PHP中創建壓縮的RAR文件

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

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

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

G. 為什麼php創建zip文件不管用

請參考php手冊,函數特點-壓縮與歸檔擴展部分

下面是手冊實例一:

<?php

$zip=newZipArchive();
$filename="./test112.zip";

if($zip->open($filename,ZIPARCHIVE::CREATE)!==TRUE){
exit("cannotopen<$filename> ");
}

$zip->addFromString("testfilephp.txt".time(),"#.txt. ");
$zip->addFromString("testfilephp2.txt".time(),"#.txt. ");
$zip->addFile($thisdir."/too.php","/testfromfile.php");
echo"numfiles:".$zip->numFiles." ";
echo"status:".$zip->status." ";
$zip->close();
?>

H. php ZipArchive 能否在指定目錄生成壓縮包

當然可以啊,親


下面代碼就是在/tmp目錄下生成aaaa.zip文件

$zip=newZipArchive();
$zip->open('/tmp/aaaa.zip',ZipArchive::CREATE);
$zip->addEmptyDir('dir1');
$zip->close();

I. php如何生成自解壓文件

php ZipArchive 能否在指定目錄生成壓縮包

初步接觸ZipArchive , 目前發現 ZipArchive類生成的zip壓縮包是存儲在 ppublic function backupfiles(){ $filename = "backups/". time().".zip"; $zip = new \ZipArchive(); $zip->open($filename,\ZipArchive::CREATE); $path = 'demo';//指定的目錄 $this->addFileToZip($path, $zip); } public function addFileT

如何用PHP創建一個加密的zip壓縮文件

/* creates a compressed zip file */function create_zip($files = array(),$destination = '',$overwrite = false) { //if the zip file already exists and overwrite is false, return false if(file_exists($destination) && 。

PHP-php生成zip壓縮文件如何給該文件加解壓縮密碼
php如何壓縮一個文件夾裡面所有的文件到zip文件裡面?

//函數:文件壓縮//壓縮參數:需要壓縮的文件或文件夾(文件可為數組),壓縮後的zip文件名及存放路徑,壓縮類型1:文件夾2:文件,後續操作1:壓縮後下載;2:存放在伺服器上(默認為/@Upload下)//壓縮文件夾示例:Tozip("./","../".date("d-H-i-s").".zip",1

如何在PHP中創建壓縮的RAR文件

$filename = "./" . date ( 'YmdH' ) . ".zip"; // 最終生成的文件名(含路徑) // 生成文件 $zip = new ZipArchive (); // 使用本類,linux需開啟zlib,windows需取消php_zip.dll前的注釋 if ($zip->open ( $filename, ZIPARCHIVE::CREATE ) 。

看你的內存是多大了,只要你的虛擬內存和物理內存夠大。

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

要用PHP壓縮解壓文件,常用的方法是調用命令行去執行解壓縮操作 可以用exec() 、system()等函數調用shell命令 Linux下解壓縮命令是tar [-cxtzjvfpPN] 文件與目錄,tar命令可以壓縮解壓.tar、.gz、.tar.gz、.tgz、.bz

請高手指點:PHP 如何解壓縮zip格式壓縮的文件或壓zip格式壓縮了幾個文件,或壓縮了一個文件夾,文件夾里有多個文件, 現/** * PHP在線壓縮/解壓實例 */ date_default_timezone_set('prc'); $zip = new engine_compress_decompress(); if (isset($_POST)) { $sourcePath = ''; //默認位置 if (isset($_FILES['upfile'])) //上傳文件 { $stmp = $zip->fileUpload('upf

以上就是CSS布局HTML為大家整理的php生成zip壓縮文件的方法詳解 技術分享內容,如果覺得小編的資源對您有幫助 不要忘記分享給您身邊的朋友哦!

J. 創建一個加密的ZIP文件的PHP問題,怎麼解決

官網類:

classHZip
{
/**
*Addfilesandsub-directoriesinafoldertozipfile.
*@paramstring$folder
*@paramZipArchive$zipFile
*@paramint$.
*/
($folder,&$zipFile,$exclusiveLength){
$handle=opendir($folder);
while(false!==$f=readdir($handle)){
if($f!='.'&&$f!='..'){
$filePath="$folder/$f";
//.
$localPath=substr($filePath,$exclusiveLength);
if(is_file($filePath)){
$zipFile->addFile($filePath,$localPath);
}elseif(is_dir($filePath)){
//Addsub-directory.
$zipFile->addEmptyDir($localPath);
self::folderToZip($filePath,$zipFile,$exclusiveLength);
}
}
}
closedir($handle);
}

/**
*Zipafolder(includeitself).
*Usage:
*HZip::zipDir('/path/to/sourceDir','/path/to/out.zip');
*
*@paramstring$.
*@paramstring$outZipPathPathofoutputzipfile.
*/
publicstaticfunctionzipDir($sourcePath,$outZipPath)
{
$pathInfo=pathInfo($sourcePath);
$parentPath=$pathInfo['dirname'];
$dirName=$pathInfo['basename'];

$z=newZipArchive();
$z->open($outZipPath,ZIPARCHIVE::CREATE);
$z->addEmptyDir($dirName);
self::folderToZip($sourcePath,$z,strlen("$parentPath/"));
$z->close();
}
}
使用此類可以添加文件夾
Hzip::zipDir(『d://www/aa/』,d://aa.zip);
如果添加多個文件夾到一個zip包需要重復調用
如果想繼續在zip包中增加文件:
$zip=newZipArchive();
$zip->open(d://aa.zip)
$zip->addFile('d://www/aa.txt','aa.txt');
如果需要增加多個使用循環添加
$zip->close();
<?php
/**
*CreatedbyPhpStormsite:www.5wx.org.
*User:tc
*/

classZip
{
public$pathExe;
public$agent='linux';
publicfunction__construct(){
$this->pathExe=dirname(__FILE__);
$agent=strtolower(PHP_OS);
if(strstr($agent,'win')){
$this->agent='win';
}
}

publicfunctionzip($sourcePath,$fileList=array(),$outPath,$zipName,$password='',$relative="../../../vendor/Zip/"){
try{
$fileStr=implode("",$fileList);
chdir($sourcePath);
$sourcePath=$this->pathDeal($sourcePath);
$zipbool=true;
if($zipbool){
if($this->agent=='win'){
if($password==''){
exec('"'.$this->pathExe.DIRECTORY_SEPARATOR.'zip.exe"'."-q-r".$zipName."".$fileStr);
}else{
exec('"'.$this->pathExe.DIRECTORY_SEPARATOR.'zip.exe"'."-q-r-P".$password."".$zipName."".$fileStr);
}
}else{
if($password==''){
exec("zip-q-r".$zipName."".$fileStr);
}else{
exec("zip-q-r-P".$password."".$zipName."".$fileStr);
}
}
$outPath=$this->pathDeal($outPath);
if(file_exists($sourcePath.DIRECTORY_SEPARATOR.$zipName)){
$bool=($sourcePath.DIRECTORY_SEPARATOR.$zipName,$outPath.DIRECTORY_SEPARATOR.$zipName);
if($bool){
returnjson_encode(array('result'=>true,'message'=>''));
}else{
returnjson_encode(array('result'=>false,'message'=>'zipisexistbutnottooutpath'));
}
}else{
returnjson_encode(array('result'=>false,'message'=>'ziperror'));
}
}else{
returnjson_encode(array('result'=>false,'message'=>'zipcommanderror'));
}
}catch(Exception$e){
returnjson_encode(array('result'=>true,'message'=>json_encode($e)));
}
}
protectedfunctionpathDeal($path){
$lastword=substr($path,-1);
if($lastword==DIRECTORY_SEPARATOR){
$path=substr($path,0,-1);
}
return$path;
}

publicfunctionunzip($sourceZip,$destination,$password){
try{
if($this->agent=='win'){
chdir($this->pathExe);
exec("unzip.exe-o-P".$password."".'"'.$sourceZip.'"'."-d".'"'.$destination.'"',$res,$return);
}else{
exec("unzip-o-P".$password."".$sourceZip."-d".$destination,$res,$return);
}

returnjson_encode(array('result'=>true,'message'=>''));
}catch(Exception$e){
returnjson_encode(array('result'=>true,'message'=>json_encode($e)));
}
}
}

閱讀全文

與php創建zip相關的資料

熱點內容
郵件電子伺服器是什麼 瀏覽:909
電腦軟體加密保護軟體 瀏覽:195
java迴文素數 瀏覽:368
愛愛影視倫理片 瀏覽:849
電影更新最快 瀏覽:612
熱門推薦中文字幕1 瀏覽:674
成龍五行拳電影叫什麼 瀏覽:718
加密110報警點位 瀏覽:707
同花順指標編程 瀏覽:572
小米應用雙開如何加密 瀏覽:180
rsa的加密優勢 瀏覽:243
佛教電影在線觀看 瀏覽:754
韓劇電影免費觀看 瀏覽:685
日本劇情劇電影 瀏覽:969
2017最火編程語言 瀏覽:406
化合價演算法 瀏覽:349
海康威視發卡都是加密的嗎 瀏覽:848
快穿女主黃黃小說推薦 瀏覽:627
主角在美洲建國 瀏覽:969
葉天明柳韻的小說叫什麼 瀏覽:325