當前位置:首頁 » 文件管理 » php壓縮代碼

php壓縮代碼

發布時間: 2025-02-20 21:34:35

A. 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,

B. 求php壓縮解壓rar和zip類源碼

不用寫,rar演算法是有專利權的

RAR壓縮演算法是RARLab的專利,其它軟體要使用或自己實現RAR演算法的實作,都是要向RARLab申請許可或交錢的

zip演算法php有自帶的函數
====>
需求
PHP 4
The bundled PHP 4 version requires » ZZIPlib, by Guido Draheim, version 0.10.6 or later

PHP 5.2.0 or later
This extension uses the functions of » zlib by Jean-loup Gailly and Mark Adler.
=====>
所以用RAR只有通過命令行調用已經安裝的rar程序實現打包,效果是一樣的.具體調用方法參考各自軟體說明.winrar也能用命令行調用,請看http://ke..com/view/2345.htm

C. php header 下載zip文件的問題

<?php
include("class.php");
date_default_timezone_set("PRC");//設置時區為中國
$filetype_array = array("as"=>"Flash ActionScript File","bmp"=>"BMP圖像"
,"doc"=>"Microsoft Word文檔","rar"=>"WinRAR 壓縮文檔",
"ppt"=>"Microsoft PowerPoint 演示文稿","txt"=>"文本文檔",
"xls"=>"Microsoft Excel 工作表","gif"=>"GIF圖像",
"jpg"=>"JPEG圖像","jpeg"=>"JPEG圖像","png"=>"PNG圖像",
"html"=>"HTML Document","htm"=>"HTML Document",
"mp3"=>"MP3 格式聲音","chm"=>"已編譯的HTML幫助文件",
"fla"=>"Flash Document","mdb"=>"Microsoft Access 應用程序",
"pdf"=>"PDF 文件","swf"=>"Flash Movie","xml"=>"XML 文檔",
"zip"=>"WinRAR ZIP 壓縮文件","asf"=>"Windows 音頻/視頻文件",
"wmv"=>"Windows Media 音頻/視頻文件","avi"=>"視頻剪輯",
"mpeg"=>"電影剪輯","exe"=>"應用程序","gz"=>"WinRAR 壓縮文件",
"tar"=>"WinRAR 壓縮文件","tiff"=>"TIFF 文件");

//以上為判斷函數
$="./images";
$nba=opendir($);
$i=1;
echo "<table border=1px color:red>";
echo "<tr><td>I D</td><td>文件名稱</td><td>大小</td><td>最後修改時間</td><td>類型</td><td>下載</td></tr>";
while ($wnba=readdir($nba))
{

if($wnba != "." && $wnba != "..")

{
$path=$."/".$wnba;
$dir=new dir($path);
$str[]=
"<tr>".
"<td>".$i++."</td>".
"<td>".$wnba."</td>".
"<td>".$dir->getsize()."</td>".
"<td>".$dir->gettime()."</td>".
"<td>".$dir->gettype()."</td>".
"<td><a href='$path'><img src=".$dir->getIcon()."></a></td>".
"</tr>\n";

}
$lines=15;//每頁15行
if( " "==$cur_page) $cur_page=1;//當前頁
$page=ceil(count($str)/$lines);//頁數
echo $page;
for($i=($cur_page-1)*$lines ; $i <$cur_page*$lines ; $i++){//分段讀出數組
echo "$str[$i] ";
}

}
echo "</table>";
closedir($nba);

?>
<table width=100%> <tr> <td align=center>
<?
for ($i=1;$i <=$page;$i++){
$i==$cur_page ? $a= " <b> ".$i. " </b> " : $a= " <a href= ".wjclass1.php. "?cur_page=$i> ".$i. " </a> ";
echo "$a ";
}
?>
</td> </tr> </table>
</td>
</tr>
</table>

D. php 怎把上傳的rar zip文件 自動解壓 用的是哪個函數 求高手指點 告急 謝謝 求源代碼

/**
* PHP在線壓縮/解壓實例
*/

date_default_timezone_set('prc');

$zip = new engine_compress_decompress();

if (isset($_POST))
{
$sourcePath = ''; //默認位置

if (isset($_FILES['upfile'])) //上傳文件
{
$stmp = $zip->fileUpload('upfile');
$sourcePath = $stmp['sourcefile'];
$upfileError = $stmp['error'];
}
elseif (isset($_POST['inputfile'])) //輸入目錄或者文件
{
$sourcePath = $_POST['inputfile'];
}
elseif (isset($_POST['decompresssourcefiles'])) //解壓縮提交
{
$isDecompress = $zip->decompress($_POST['decompresssourcefiles'], $_POST['topath']);
if (!empty($isDecompress['filelist']))
{
$href = '<script type="text/javascript" language="javascript">window.location.href=\'#decompress\'</script>';
}

}

$fileList = $zip->fileArray($sourcePath); //解壓縮文件列表

if (isset($_POST['compressinputfileorfolder'])) //壓縮文件目錄或者文件輸入
{
$sourcePath = $_POST['compressinputfileorfolder'];
$href = '<script type="text/javascript" language="javascript">window.location.href=\'#compress\'</script>';
$compressFilelist = $zip->compressFileArray($sourcePath); //壓縮文件列表
}
elseif ((isset($_POST['selectcompressfilelist'])) && (isset($_POST['compresssavefilename'])))
{
$compressFiles = $zip->compress($_POST['selectcompressfilelist'], $_POST['compresssavefilename']); //真實檢測
$isCompress = $zip->CompileZipFile($compressFiles, $zip->savePath, 'all');
if (!empty($isCompress))
{
$href = '<script type="text/javascript" language="javascript">window.location.href=\'#compress\'</script>';
}
}
}

E. php 壓縮文件夾

php將文件夾打包成zip文件,參考代碼如下:

functionaddFileToZip($path,$zip){
$handler=opendir($path);//打開當前文件夾由$path指定。
while(($filename=readdir($handler))!==false){
if($filename!="."&&$filename!=".."){//文件夾文件名字為'.'和『..』,不要對他們進行操作
if(is_dir($path."/".$filename)){//如果讀取的某個對象是文件夾,則遞歸
addFileToZip($path."/".$filename,$zip);
}else{//將文件加入zip對象
$zip->addFile($path."/".$filename);
}
}
}
@closedir($path);
}

$zip=newZipArchive();
if($zip->open('images.zip',ZipArchive::OVERWRITE)===TRUE){
addFileToZip('images/',$zip);//調用方法,對要打包的根目錄進行操作,並將ZipArchive的對象傳遞給方法
$zip->close();//關閉處理的zip文件
}
熱點內容
c語言截斷 發布:2025-02-22 00:02:11 瀏覽:390
康福最新伺服器地址是多少 發布:2025-02-22 00:01:23 瀏覽:369
w10怎麼關閉登錄密碼 發布:2025-02-21 23:58:25 瀏覽:438
126smtp伺服器地址 發布:2025-02-21 23:52:12 瀏覽:644
腳本幽默 發布:2025-02-21 23:52:03 瀏覽:52
伺服器電腦大概價格 發布:2025-02-21 23:50:34 瀏覽:893
怎麼在電腦里看它的配置 發布:2025-02-21 23:48:17 瀏覽:133
我的世界手機版開兩人伺服器 發布:2025-02-21 23:42:54 瀏覽:997
華為的直播精靈如何配置 發布:2025-02-21 23:40:20 瀏覽:129
mariadbforlinux 發布:2025-02-21 23:30:48 瀏覽:393