Skip to content

Instantly share code, notes, and snippets.

@fchaussin
Last active May 16, 2019 10:24
Show Gist options
  • Save fchaussin/368e40e276e0abce1fdf497a8199f63f to your computer and use it in GitHub Desktop.
Save fchaussin/368e40e276e0abce1fdf497a8199f63f to your computer and use it in GitHub Desktop.
Script PHP d'extraction ZIP
<?php
$zipfiles = glob('*.{zip}', GLOB_BRACE);
$options = "";
foreach($zipfiles as $file){
$options .= "<option value='{$file}'>{$file}</option>";
}
?>
<style>
body{font-family:sans-serif;font-size:20px;width:100%;max-width:900px;margin:0 auto;}
.text{background:rgba(0,0,0,.05);padding:2em; text-align: center;}
h1,h2,h3{background:#111; color:#fff; padding:1em; text-align: center}
h3{background:#333;}
.ok{background:#3d3;}.ko{background:#d33;}i{color:#dd3;}
</style>
<h1>UNZIP</h1>
<hr>
<div class="text">
<form method="POST">
<label>Fichier zip :</label>
<select name="file"><?=$options?></select>
<input type="submit" value="ok">
</form>
</div>
<hr>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
set_time_limit (300);
if(isset($_POST['file'])){
echo "<h3>Extraction de <i>{$_POST['file']}</i> en cours...</h3>";
$zip = new ZipArchive;
$res = $zip->open($_POST['file']);
if ($res === TRUE) {
$zip->extractTo('./');
$zip->close();
echo '<h2 class="ok">OK :)</h2>';
} else {
echo '<h2 class="ko">échec :(<br></h2><hr>';
}
echo '<pre>';var_dump($res,$zip);echo '</pre>';
}else{
echo '<h2>saisir le nom du fichier et cliquer sur ok</h2>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment