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>

相关文章

使用zend studio for eclipse不能激活代码提示功能的解决办法

其实这是项目没有经过zend studio for eclipse 编译(应该是建立索引吧)导致的,那么就只要让它重新编译项目代码即可。 操作如下: 随便新建一个项目,比如test。然后...

php日志函数error_log用法实例分析

本文实例讲述了php日志函数error_log用法。分享给大家供大家参考,具体如下: php内置打印log日志的函数,这个对php程序调试非常高效 1.配置 编辑php.ini文件...

分享PHP守护进程类

用PHP实现的Daemon类。可以在服务器上实现队列或者脱离 crontab 的计划任务。  使用的时候,继承于这个类,并重写 _doTask 方法,通过 main 初始化执...

深入分析PHP优化及注意事项

1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍。 当然了,这个测试方法需要在十万级以上次执行,效果才明显。 其实静态...

php mssql 日期出现中文字符的解决方法

比如:2005-12-23 读出以后页面会显示为:2005 十二月 23 ,这样给程序处理带来很多不便。查找了一些资料发现是php.ini默认了日期处理功能。 解决方法为: 第一个方法:...