Created
July 26, 2024 14:47
-
-
Save me-suzy/b7cc7dcc32976f5d83d3200e0d5ddf1c to your computer and use it in GitHub Desktop.
dezarhivare zip files din foldere cu ajutorul php Cpanel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// activa extensia zip din cPanel la "Select php version" sectiunea module. // Selecteaza mai intai optiunea .zip | |
// https://core13.spatiul.ro:2083/cpsess1391315882/frontend/jupiter/lveversion/php_selector.live.pl#/extensions | |
// save file as unzip_realtime.php and then access from browser https://YOUR WEBSITE/unzip_realtime.php | |
<?php | |
ini_set('display_errors', 1); | |
error_reporting(E_ALL); | |
set_time_limit(0); | |
ini_set('output_buffering', 'off'); | |
ini_set('zlib.output_compression', false); | |
while (@ob_end_flush()); | |
ini_set('implicit_flush', true); | |
ob_implicit_flush(true); | |
$root_dir = '/home/neculaif/public_html'; | |
$predefined_subdirs = [ | |
'af', 'ak', 'am', 'ar', 'as', 'ay', 'az', 'be', 'bg', 'bho', 'bm', 'bn', 'bs', 'ca', 'ceb', 'ckb', 'co', 'cs', 'cy', 'da', 'dhivehi', 'dogri', 'doi', 'dutch', 'dv', 'eo', 'esperanto', 'estonian', 'et', 'ewe', 'france', 'ht', 'hy', 'id', 'ig', 'ilo', 'it', 'iw', 'ja', 'jw', 'ka', 'km', 'ko', 'kri', 'ky', 'lb', 'lg', 'ln', 'lt', 'lv', 'mk', 'ml', 'mn', 'mr', 'ms', 'my', 'nl', 'no', 'nso', 'om', 'or', 'pt', 'qu', 'sa', 'si', 'sk', 'sm', 'sn', 'so', 'sq', 'st', 'su', 'sv', 'ta', 'tg', 'th', 'ti', 'tl', 'tt' | |
]; | |
$success_count = 0; | |
$fail_count = 0; | |
$total_dirs = count($predefined_subdirs); | |
header('Content-Type: text/html; charset=utf-8'); | |
echo " | |
<!DOCTYPE html> | |
<html lang='en'> | |
<head> | |
<meta charset='UTF-8'> | |
<meta name='viewport' content='width=device-width, initial-scale=1.0'> | |
<title>Dezarhivare în progres</title> | |
<style> | |
body { font-family: Arial, sans-serif; line-height: 1.6; padding: 20px; } | |
.progress-bar { width: 100%; background-color: #f0f0f0; padding: 3px; border-radius: 3px; box-shadow: inset 0 1px 3px rgba(0, 0, 0, .2); } | |
.progress-bar-fill { height: 22px; background-color: #4CAF50; border-radius: 3px; transition: width 500ms ease-in-out; } | |
#progress-text { margin-top: 10px; } | |
</style> | |
</head> | |
<body> | |
<h1>Procesare fișiere 1.zip</h1> | |
<div class='progress-bar'> | |
<div class='progress-bar-fill' style='width: 0;'></div> | |
</div> | |
<div id='progress-text'>Progres: 0%</div> | |
<div id='log'></div> | |
<script> | |
function updateProgress(percent) { | |
document.querySelector('.progress-bar-fill').style.width = percent + '%'; | |
document.getElementById('progress-text').innerText = 'Progres: ' + percent + '%'; | |
} | |
function logMessage(message) { | |
document.getElementById('log').innerHTML += message + '<br>'; | |
window.scrollTo(0, document.body.scrollHeight); | |
} | |
</script> | |
"; | |
function echoFlush($string) { | |
echo $string; | |
echo str_pad('', 4096); | |
flush(); | |
} | |
foreach ($predefined_subdirs as $index => $subdir) { | |
$dir_path = $root_dir . '/' . $subdir; | |
$zip_path = $dir_path . '/1.zip'; | |
$percent = round(($index / $total_dirs) * 100); | |
echoFlush("<script>updateProgress($percent); logMessage('<h3>Procesare director: $subdir</h3>');</script>"); | |
if (!is_dir($dir_path)) { | |
echoFlush("<script>logMessage('<p>Directorul $subdir nu există.</p>');</script>"); | |
continue; | |
} | |
if (!file_exists($zip_path)) { | |
echoFlush("<script>logMessage('<p>Fișierul 1.zip nu există în directorul $subdir.</p>');</script>"); | |
continue; | |
} | |
$zip = new ZipArchive; | |
if ($zip->open($zip_path) === TRUE) { | |
$zip->extractTo($dir_path); | |
$zip->close(); | |
echoFlush("<script>logMessage('<p style=\"color: green;\">Fișierul 1.zip din $subdir a fost dezarhivat cu succes.</p>');</script>"); | |
$success_count++; | |
} else { | |
echoFlush("<script>logMessage('<p style=\"color: red;\">Eroare la dezarhivarea fișierului 1.zip din $subdir.</p>');</script>"); | |
$fail_count++; | |
} | |
usleep(100000); // O mică pauză pentru a permite browserului să se actualizeze | |
} | |
echoFlush("<script> | |
updateProgress(100); | |
logMessage('<h2>Sumar</h2>'); | |
logMessage('<p>Total directoare procesate: $total_dirs</p>'); | |
logMessage('<p>Dezarhivări reușite: $success_count</p>'); | |
logMessage('<p>Dezarhivări eșuate: $fail_count</p>'); | |
</script>"); | |
echo "</body></html>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment