php線上打包工具

來源:互聯網
上載者:User

標籤:type   span   log   head   merge   new   logs   iar   打包   

一哥們要實現 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>

 文章來源:https://www.xiariboke.com/codes/1595.html

php線上打包工具

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.