php 在线打包_支持子目录

yipeiwu_com5年前PHP代码库
程序使用了php的zip扩展,如果服务器支持,那就可以用了^_^,生成的zip压缩包可以用winrar等来解压的,当然也可以用php来解压。解压的过段时间再发布了。

<?php    
$button=$_POST['button'];    
if($button=="开始打包")    
{    
    $zip = new ZipArchive();    
    $filename = "./".date("Y-m-d")."_".md5(time())."_jackfeng.zip";    
    if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {    
        exit("无法创建 <$filename>\n");    
        }    
    $files = listdir();    
    foreach($files as $path)    
    {    
        $zip->addFile($path,str_replace("./","",str_replace("\\","/",$path)));   
    }   
    echo "压缩完成,共压缩了: " . $zip->numFiles . "个文件\n";   
    $zip->close();   
}   
Function listdir($start_dir='.') {   
  $files = array();   
  if (is_dir($start_dir)) {   
   $fh = opendir($start_dir);   
   while (($file = readdir($fh)) !== false) {   
     if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;   
     $filepath = $start_dir . '/' . $file;   
     if ( is_dir($filepath) )   
       $files = array_merge($files, listdir($filepath));   
     else   
       array_push($files, $filepath);   
   }   
   closedir($fh);   
  } else {   
   $files = false;   
  }   
 return $files;   
}   
?>   
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >    
<html>    
    <head>    
        <title>在线打包工具</title>    
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">   
    </head>   
    <body>   
        <form name="form1" method="post" action="">   
            <hr size="1">   
            <h3><a href="?">在线打包工具</a></h3>   
            <P> <input type="submit" name="button" value="开始打包" /></P>    
            <P>说明:点开始打包,之后,就是耐心等待打包完成了,根据网站文件多少,需要的时间可能会很长。打包完成之后,压缩包会存放在要打包的站点目录下,以<span style='color:red;'>打包时间+不定长随机字符串+jackfeng.zip</span>这样命名,请登陆ftp后下载。</P>    
        </form>    
    </body>    
</html>

相关文章

php将print_r处理后的数据还原为原始数组的解决方法

PHP print_r方法可以把变量打印显示,使变量易于理解。如果变量是string,integer或float,将打印变量值本身,如果变量是array,将会按照一定格式显示键和元素。o...

php curl上传、下载、https登陆实现代码

1、curl下载 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "ftp://127.0.0.1/downtest.txt");...

分享php分页的功能模块

分享php分页的功能模块

先贴张图看看效果 在贴一下代码吧 <?php $localhost = "localhost"; $username = "root"; $password =...

PHP中静态变量的使用方法实例分析

本文实例讲述了PHP中静态变量的使用方法。分享给大家供大家参考,具体如下: 1.定义静态变量 public static $endpoint,$accessKeyId,$access...

数组与类使用PHP的可变变量名需要的注意的问题

有时候可变的变量名会给编程带来很大的方便。也就是说变量名可以被动态的命名和使用。通常变量通过下面这样的语句来命名 :$a = 'hello';可变变量名指的是使用一个变量的值作为这个变量...