Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <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>
- <?php
- $action = "start"; $directory = "."; $zipfile = "bckup".date("Y-m-d-H-i-s").".zip";
- echo '<table><thead><tr><th> <th>Priečinok<th>Názov archívu<th> <tbody>';
- echo "<tr><th><form action='./zip.php' method='post'>"
- . " <td><input type='text' name='directory' value='.'>*"
- . " <td><input type='text' name='zipfile' value='".date("Y-m-d-H-i-s").".zip'>"
- . " <td><input type='hidden' name='action' value='start'><input type='submit' value='Zbaliť'></form>";
- echo '</table>';
- if ($action == "start") {
- $filenames = array();
- function browse($dir) {
- global $filenames;
- if ($handle = opendir($dir)) {
- while (false !== ($file = readdir($handle))) {
- if ($file != "." && $file != ".." && is_file($dir.'/'.$file)) {
- $filenames[] = $dir.'/'.$file;
- }
- else if ($file != "." && $file != ".." && is_dir($dir.'/'.$file)) {
- browse($dir.'/'.$file);
- }
- }
- closedir($handle);
- }
- return $filenames;
- }
- browse($directory);
- $zip = new ZipArchive();
- if ($zip->open($zipfile, ZIPARCHIVE::CREATE)!==TRUE) {
- exit("cannot open <$zipfile>\n");
- }
- ?><h2>Výsledky <small>(zbaľovania)</small></h2><?php
- echo '<ol class="messages">';
- foreach ($filenames as $filename) {
- echo "<li class='message ok'>Súbor <em><b>$filename</b></em> pridaný.";
- $zip->addFile($filename,$filename);
- }
- echo '</ol>';
- 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>";
- else echo "<p class='message error'>Súbory sa nepodarilo zbaliť!</p>";
- $zip->close();
- }
- ?></body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement