VanGans

Zipper (Web Bassed)

Apr 19th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 13.96 KB | None | 0 0
  1. <?
  2. @set_time_limit(3600);
  3. $conf['dir'] = "onevnzip";
  4. if ((isset($_GET['step']))&&(!empty($_GET['step']))) $step=$_GET['step']; else $step=0;
  5. if ((isset($_GET['dirname']))&&(!empty($_GET['dirname']))) $dirname=$_GET['dirname']; else $dirname=".";
  6. $dirname = str_replace("../","",$dirname);
  7. class zipfile
  8. {
  9.     var $datasec      = array();
  10.     var $ctrl_dir     = array();
  11.     var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
  12.     var $old_offset   = 0;
  13.     function unix2DosTime($unixtime = 0) {
  14.         $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
  15.  
  16.         if ($timearray['year'] < 1980) {
  17.             $timearray['year']    = 1980;
  18.             $timearray['mon']     = 1;
  19.             $timearray['mday']    = 1;
  20.             $timearray['hours']   = 0;
  21.             $timearray['minutes'] = 0;
  22.             $timearray['seconds'] = 0;
  23.         } // end if
  24.  
  25.         return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |
  26.                 ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
  27.     } // end of the 'unix2DosTime()' method
  28.  
  29.     function addFile($data, $name, $time = 0)
  30.     {
  31.         $name     = str_replace('\\', '/', $name);
  32.  
  33.         $dtime    = dechex($this->unix2DosTime($time));
  34.         $hexdtime = '\x' . $dtime[6] . $dtime[7]
  35.                   . '\x' . $dtime[4] . $dtime[5]
  36.                   . '\x' . $dtime[2] . $dtime[3]
  37.                   . '\x' . $dtime[0] . $dtime[1];
  38.         eval('$hexdtime = "' . $hexdtime . '";');
  39.  
  40.         $fr   = "\x50\x4b\x03\x04";
  41.         $fr   .= "\x14\x00";            // ver needed to extract
  42.         $fr   .= "\x00\x00";            // gen purpose bit flag
  43.         $fr   .= "\x08\x00";            // compression method
  44.         $fr   .= $hexdtime;             // last mod time and date
  45.  
  46.         // "local file header" segment
  47.         $unc_len = strlen($data);
  48.         $crc     = crc32($data);
  49.         $zdata   = gzcompress($data);
  50.         $zdata   = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug
  51.         $c_len   = strlen($zdata);
  52.         $fr      .= pack('V', $crc);             // crc32
  53.         $fr      .= pack('V', $c_len);           // compressed filesize
  54.         $fr      .= pack('V', $unc_len);         // uncompressed filesize
  55.         $fr      .= pack('v', strlen($name));    // length of filename
  56.         $fr      .= pack('v', 0);                // extra field length
  57.         $fr      .= $name;
  58.  
  59.         // "file data" segment
  60.         $fr .= $zdata;
  61.  
  62.         // "data descriptor" segment (optional but necessary if archive is not
  63.         // served as file)
  64.         $fr .= pack('V', $crc);                 // crc32
  65.         $fr .= pack('V', $c_len);               // compressed filesize
  66.         $fr .= pack('V', $unc_len);             // uncompressed filesize
  67.  
  68.         // add this entry to array
  69.         $this -> datasec[] = $fr;
  70.  
  71.         // now add to central directory record
  72.         $cdrec = "\x50\x4b\x01\x02";
  73.         $cdrec .= "\x00\x00";                // version made by
  74.         $cdrec .= "\x14\x00";                // version needed to extract
  75.         $cdrec .= "\x00\x00";                // gen purpose bit flag
  76.         $cdrec .= "\x08\x00";                // compression method
  77.         $cdrec .= $hexdtime;                 // last mod time & date
  78.         $cdrec .= pack('V', $crc);           // crc32
  79.         $cdrec .= pack('V', $c_len);         // compressed filesize
  80.         $cdrec .= pack('V', $unc_len);       // uncompressed filesize
  81.         $cdrec .= pack('v', strlen($name) ); // length of filename
  82.         $cdrec .= pack('v', 0 );             // extra field length
  83.         $cdrec .= pack('v', 0 );             // file comment length
  84.         $cdrec .= pack('v', 0 );             // disk number start
  85.         $cdrec .= pack('v', 0 );             // internal file attributes
  86.         $cdrec .= pack('V', 32 );            // external file attributes - 'archive' bit set
  87.  
  88.         $cdrec .= pack('V', $this -> old_offset ); // relative offset of local header
  89.         $this -> old_offset += strlen($fr);
  90.  
  91.         $cdrec .= $name;
  92.  
  93.         // optional extra field, file comment goes here
  94.         // save to central directory
  95.         $this -> ctrl_dir[] = $cdrec;
  96.     } // end of the 'addFile()' method
  97.  
  98.     function file()
  99.     {
  100.         $data    = implode('', $this -> datasec);
  101.         $ctrldir = implode('', $this -> ctrl_dir);
  102.  
  103.         return
  104.             $data .
  105.             $ctrldir .
  106.             $this -> eof_ctrl_dir .
  107.             pack('v', sizeof($this -> ctrl_dir)) .  // total # of entries "on this disk"
  108.             pack('v', sizeof($this -> ctrl_dir)) .  // total # of entries overall
  109.             pack('V', strlen($ctrldir)) .           // size of central dir
  110.             pack('V', strlen($data)) .              // offset to start of central dir
  111.             "\x00\x00";                             // .zip file comment length
  112.     } // end of the 'file()' method
  113.    
  114.     function addFiles($files /*Only Pass Array*/)
  115.     {
  116.         foreach($files as $file) {
  117.             if (is_file($file)) //directory check
  118.             {
  119.                 $data = implode("",file($file));
  120.                 $this->addFile($data,$file);
  121.             } else {
  122. //              $data = implode("",file("lynkfziper.txt"));
  123. //              $this->addFile($data,$file."/onevnzip.txt");
  124.             }  
  125.         }
  126.     }
  127.    
  128.     function output($file)
  129.     {
  130.         $fp=fopen($file,"w");
  131.         fwrite($fp,$this->file());
  132.         fclose($fp);
  133.     }
  134.  
  135. } // end class
  136. //===================================
  137. function getdir($path=".") {
  138. global $dirarray,$conf,$dirsize;   
  139. if ($dir = opendir($path)) {
  140.   while (false !== ($entry = @readdir($dir))) {
  141.      if (($entry!=".")&&($entry!="..")) {
  142.         $lastdot = strrpos($entry,".");
  143.         $ext = chop(strtolower(substr($entry,$lastdot+1)));
  144.         $fname = substr($entry,0,$lastdot);
  145.         if ($path!=".") $newpath = $path."/".$entry;
  146.         else $newpath = $entry;
  147.         $newpath = str_replace("//","/",$newpath);
  148.  
  149.         if (($entry!="onevnzip.php")&&($entry!="onevnzip.txt")&&($entry!=$conf['dir'])) {
  150.             $dirarray[] = $newpath;
  151.             if ($fsize=@filesize($newpath)) $dirsize+=$fsize;
  152.             if (is_dir($newpath)) getdir($newpath);
  153.         }
  154.      }
  155.   }
  156. }
  157. }// end func
  158. //===================================
  159. function getcurrentdir($path=".") {
  160. global $conf;  
  161. $dirarr = array();
  162. if ($dir = opendir($path)) {
  163.   while (false !== ($entry = @readdir($dir))) {
  164.      if (($entry!=".")&&($entry!="..")) {
  165.         $lastdot = strrpos($entry,".");
  166.         $ext = chop(strtolower(substr($entry,$lastdot+1)));
  167.         $fname = substr($entry,0,$lastdot);
  168.         if ($path!=".") $newpath = $path."/".$entry;
  169.         else $newpath = $entry;
  170.         $newpath = str_replace("//","/",$newpath);
  171.  
  172.         if (($entry!="onevnzip.php")&&($entry!="onevnzip.txt")&&($entry!=$conf['dir'])) {
  173.             $dirarr[] = $newpath;
  174.         }
  175.      }
  176.   }
  177. }
  178. return $dirarr;
  179. }// end func
  180. //=========================
  181. function size_format($bytes="") {
  182.   $retval = "";
  183.   if ($bytes >= 1048576) {
  184.     $retval = round($bytes / 1048576 * 100 ) / 100 . " MB";
  185.   } else if ($bytes  >= 1024) {
  186.         $retval = round($bytes / 1024 * 100 ) / 100 . " KB";
  187.     } else {
  188.         $retval = $bytes . " bytes";
  189.       }
  190.   return $retval;
  191. }
  192. //=============================
  193. $currentdir = getcurrentdir($dirname);
  194. sort($currentdir);
  195. ?>
  196. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  197. <html>
  198. <head>
  199. <title>-:[ Lynk Ziper - ver 1.0 - wWw.OneVn.Net ]:-</title>
  200. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  201. <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
  202. <style type="text/css">
  203. <!--
  204. html {
  205.     overflow-x: auto;
  206.     scrollbar-face-color: #CECECE;
  207.     scrollbar-shadow-color: #6B6B6B;
  208.     scrollbar-highlight-color: #F8F8F8;
  209.     scrollbar-3dlight-color: #8A8A8A;
  210.     scrollbar-darkshadow-color: #8A8A8A;
  211.     scrollbar-track-color: #8A8A8A;
  212.     scrollbar-arrow-color: #215A8C;
  213. }
  214. body,td,th {
  215.     font-family: Verdana, Arial, Helvetica, sans-serif;
  216.     font-size: 12px;
  217.     color: #061D36;
  218. }
  219. body {
  220.     margin-left: 0px;
  221.     margin-top: 0px;
  222.     margin-right: 0px;
  223.     margin-bottom: 0px;
  224.     background-color:#DCDCDC;
  225. }
  226. a:link {
  227.     color: #FF8400;
  228.     text-decoration: none;
  229. }
  230. a:visited {
  231.     text-decoration: none;
  232.     color: #FF8400;
  233. }
  234. a:hover {
  235.     text-decoration: none;
  236.     color: #FF6600;
  237. }
  238. a:active {
  239.     text-decoration: none;
  240.     color: #FF8400;
  241. }
  242. img { border : 0px; }
  243. .bdr {
  244.     border: 1px solid #344559;
  245. }
  246. .ctittle {
  247.     font-size: 14px;
  248.     font-weight: bold;
  249.     color: #FFFFFF;
  250.     text-decoration: none;
  251.     background-color:#0063B0;
  252. }
  253. .mtittle {
  254.     font-size: 16px;
  255.     font-weight: bold;
  256.     color: #FFFFFF;
  257.     text-decoration: none;
  258.     background-color:#2B6082;
  259.     height:40px;
  260. }
  261. .ftittle {
  262.     font-size: 12px;
  263.     font-weight: bold;
  264.     color: #FFFFFF;
  265.     text-decoration: none;
  266.     background-color:#3A74AB;
  267.     height:25px;
  268. }
  269. .tittle {
  270.     font-size: 12px;
  271.     color: #FFFFFF;
  272.     text-decoration: none;
  273.     background-color:#3F668A;
  274. }
  275. .br_sp {
  276.     border-top-width: 1px;
  277.     border-top-style: dotted;
  278.     border-top-color: #003366;
  279.     color: #003333;
  280.     text-decoration: none;
  281.     font-size: 11px;
  282. }
  283. .btitle {
  284.     color: #FFFFFF;
  285.     font-weight: bold;
  286.     padding:5px;
  287. }
  288. .rowdir {
  289.     background-color:#EEEEEE;
  290.     color:#003333;
  291.     font-weight:bold;
  292. }
  293. .rowfile {
  294.     background-color:#FFFFFF;
  295. }
  296. .rowbut {
  297.     background-color:#FFFFCC;
  298. }
  299. -->
  300. </style>
  301. </head>
  302. <body>
  303. <script language="javascript">
  304. /* - - - - - - - - - - - - - - - - - - - - - - -
  305. Lynk Javascript
  306.  - - - - - - - - - - - - - - - - - - - - - - - */
  307. var ie45,ns6,ns4,dom;
  308. if (navigator.appName=="Microsoft Internet Explorer") ie45=parseInt(navigator.appVersion)>=4;
  309. else if (navigator.appName=="Netscape"){  ns6=parseInt(navigator.appVersion)>=5;  ns4=parseInt(navigator.appVersion)<5;}
  310. dom=ie45 || ns6;
  311.  
  312. function getobj(id) {
  313. el = document.all ? document.all[id] :   dom ? document.getElementById(id) :   document.layers[id];
  314. return el;
  315. }
  316.  
  317. function checkall()
  318.     {
  319.         for ( i=0;i < document.finfo.elements.length ; i++ ){
  320.             if ( document.finfo.all.checked==true ){
  321.                 document.finfo.elements[i].checked = true;
  322.             }
  323.             else
  324.             {
  325.                 document.finfo.elements[i].checked  = false;
  326.             }
  327.         }
  328.     }
  329. </script>
  330. <table width="100%" bgcolor="#1E476A" align=center border=0 cellspacing=1 cellpadding=1>
  331.     <tr>
  332.       <td align=center class="mtittle" valign="middle"><b>Lynk Ziper - ver 1.0</b></td>
  333.     <td align=center class="ftittle">Copyright 2007 by <a href="mailto:mr.lynkyul@yahoo.com.vn">wWw.OneVn.net </a></td>
  334.     </tr>
  335. </table>
  336. <br>
  337. <? if ($step!=0) { ?>
  338. <br />
  339. <table width="70%" border="0" cellspacing="2" cellpadding="3" align="center" style="border:1px #666666 solid">
  340.   <tr>
  341.     <td align="center" bgcolor="#FFFFFF" height="100"><span id="status">
  342.     <p><img src="http://img120.imageshack.us/img120/7581/loadingre0.gif" width="250" height="20" /></p>
  343.  
  344.           <p>Processing Zip Folders & Files selected .</p></span>
  345.     </td>
  346.   </tr>
  347. </table>
  348. <br>
  349. <? } else { ?>
  350. <form action="?step=1" id="finfo" name="finfo" method="post">
  351. <table width="60%" border="0" cellspacing="1" cellpadding="3" align="center" style="border:1px #999999 solid">
  352. <tr>
  353.     <td style="background-color:#2B6082; color:#FFFFFF; padding:5px;" align="left"><b>Current directory : <a href="?dirname=.">Ziper</a> <?
  354.     if ((!empty($dirname))&&($dirname!=".")) {
  355.         $lpath = explode("/",$dirname);
  356.         if (count($lpath)>1) echo "- <a href='?dirname={$lpath[0]}'>{$lpath[0]}</a>";
  357.     }
  358.     ?></b></td>
  359.   </tr>
  360. <?
  361. for ($i=0;$i<count($currentdir);$i++) {
  362.     $entry = $currentdir[$i];
  363.     if (!is_dir($entry)) {
  364.         $class="rowfile";
  365.         $name = $entry;
  366.     } else {
  367.         $class="rowdir";
  368.         $name = "<a href='?dirname={$entry}'>{$entry}</a>";
  369. //      $name = $entry;
  370.         }
  371. ?>
  372.   <tr>
  373.     <td align="left" class="<?=$class?>"><input type="checkbox" name="zdir[]" value="<?=$entry?>" />&nbsp;<?=$name?></td>
  374.   </tr>
  375. <? } ?>
  376. <tr>
  377.     <td align="left" style="background-color:#2B6082; color:#FFFFFF"><input type="checkbox" name="all"onclick="javascript:checkall();" />&nbsp;Select all</td>
  378.   </tr>
  379. </table>
  380. <br />
  381. <table width="60%" border="0" cellspacing="1" cellpadding="3" align="center" bgcolor="#FFFFFF" style="border:1px #999999 solid">
  382. <tr>
  383.     <td>File name : <input type="text" name="filename" value="onevnzip" size="40" />.zip</td>
  384.     <td align="right"><input type="submit" name="submit" value="&nbsp;&nbsp;&nbsp;Start&nbsp;&nbsp;&nbsp;" /></td>
  385.   </tr>
  386. </table>
  387. </form>
  388. <? } ?>
  389. <br>
  390. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  391.   <tr>
  392.     <td width="200" align="center" bgcolor="#3A74AB"><a href="unzip.php" class="btitle">Unzip</a></td>
  393.     <td align="center" bgcolor="#2B6082" class="btitle">&copy 2007 wWw.OneVn.Net</td>
  394.   </tr>
  395. </table>
  396. <br>
  397. </body>
  398. </html>
  399. <?
  400. if ($step==1) {
  401.     $zdir = $_POST['zdir'];
  402.     if (count($zdir)>0) {
  403.         $dirarray=array();
  404.         $dirsize=0;
  405.         $zdirsize=0;
  406.         for ($i=0;$i<count($zdir);$i++) {
  407.             $ffile = $zdir[$i];
  408.             if (is_dir($ffile)) {
  409.                 getdir($ffile);
  410.             } else {
  411.                 if ($fsize=@filesize($ffile)) $zdirsize+=$fsize;
  412.             }
  413.         }
  414.         $zdirsize+=$dirsize;
  415.         for ($i=0;$i<count($dirarray);$i++) {
  416.             $zdir[] = $dirarray[$i];
  417.         }
  418.         if (!@is_dir($conf['dir'])) {
  419.             $res = @mkdir($conf['dir'],0777);
  420.             if (!$res) $txtout = "Cannot create dir !<br>";
  421.         } else @chmod($conf['dir'],0777);
  422.    
  423.         $zipname = $_POST['filename'];
  424.         $zipname=str_replace("/","",$zipname);
  425.         if (empty($zipname)) $zipname="lynkzip";
  426.         $zipname.=".zip";
  427.        
  428.         $ziper = new zipfile();
  429.         $ziper->addFiles($zdir);
  430.         $ziper->output("{$conf['dir']}/{$zipname}");
  431.        
  432.         if ($fsize=@filesize("{$conf['dir']}/{$zipname}")) $zipsize=$fsize;
  433.         else $zipsize=0;
  434.        
  435.         $zdirsize = size_format($zdirsize);
  436.         $zipsize = size_format($zipsize);
  437.         ?>
  438.         <script language="javascript">getobj('status').innerHTML="<p><b>Zip successful !</b></p><p>Download : <a href='<?=$conf['dir']?>/<?=$zipname?>'><?=$zipname?></a></p><p>Original size : <?=$zdirsize?> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Zip size : <?=$zipsize?></p>";</script>
  439.         <?
  440.     } else {
  441.         ?><script language="javascript">getobj('status').innerHTML="No file or folder selected !";</script><?
  442.     }
  443. }
  444. ?>
Add Comment
Please, Sign In to add comment