Advertisement
Guest User

Zipovač

a guest
Oct 16th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.72 KB | None | 0 0
  1.     <html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>ZIPovač</title><meta name="robots" content="noindex,nofollow" /><style>body { padding:2em; max-width:50em; font-family:"Trebuchet MS", "Geneva CE", lucida, sans-serif;}table {border-collapse:collapse;font-size:82%;}td, th {padding:5px;border:1px solid #ddd;}th {padding-right:10px;background-color:#eee;text-align:left; font-weight:bold;}thead th {background-color:#ddd;}a {color:inherit;}small {font-size:100%; color:#ccc; font-weight:normal;}table a {color:#000; text-decoration:underline; font-weight:bold;}table a:visited {font-weight:normal;}.messages {max-height:10em; overflow-y:auto;}.message.ok {color:green;}.message.error {color:red;}</style></head><body><h2><small>[<a href='./zip.php'>obnoviť</a>]</small></h2>
  2.     <?php
  3.  
  4.       $action = "start"; $directory = "."; $zipfile = "bckup".date("Y-m-d-H-i-s").".zip";
  5.  
  6.        echo '<table><thead><tr><th>&#160;<th>Priečinok<th>Názov archívu<th> <tbody>';
  7.        echo "<tr><th><form action='./zip.php' method='post'>"
  8.            . " <td><input type='text' name='directory' value='.'>*"
  9.            . " <td><input type='text' name='zipfile' value='".date("Y-m-d-H-i-s").".zip'>"
  10.            . " <td><input type='hidden' name='action' value='start'><input type='submit' value='Zbaliť'></form>";
  11.        echo '</table>';
  12.  
  13.     if ($action == "start") {
  14.  
  15.     $filenames = array();
  16.  
  17.     function browse($dir) {
  18.     global $filenames;
  19.         if ($handle = opendir($dir)) {
  20.             while (false !== ($file = readdir($handle))) {
  21.                 if ($file != "." && $file != ".." && is_file($dir.'/'.$file)) {
  22.                     $filenames[] = $dir.'/'.$file;
  23.                 }
  24.                 else if ($file != "." && $file != ".." && is_dir($dir.'/'.$file)) {
  25.                     browse($dir.'/'.$file);
  26.                 }
  27.             }
  28.             closedir($handle);
  29.         }
  30.         return $filenames;
  31.     }
  32.  
  33.     browse($directory);
  34.  
  35.     $zip = new ZipArchive();
  36.  
  37.     if ($zip->open($zipfile, ZIPARCHIVE::CREATE)!==TRUE) {
  38.         exit("cannot open <$zipfile>\n");
  39.     }
  40.  
  41.     ?><h2>Výsledky <small>(zbaľovania)</small></h2><?php
  42.     echo '<ol class="messages">';
  43.     foreach ($filenames as $filename) {
  44.           echo "<li class='message ok'>Súbor <em><b>$filename</b></em> pridaný.";
  45.         $zip->addFile($filename,$filename);
  46.     }
  47.     echo '</ol>';
  48.  
  49.     if (($zip->status == 0)&($zip->numFiles != 0)) echo "<p class='message ok'>Celkovo pridaných <em><b>" . $zip->numFiles . "</b></em> súborov v archíve <em><b>" . $zipfile . "</b></em>.</p>";
  50.     else echo "<p class='message error'>Súbory sa nepodarilo zbaliť!</p>";
  51.     $zip->close();
  52.  
  53.     }
  54.  
  55.     ?></body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement