Skip to content

Instantly share code, notes, and snippets.

@javiertapia
Created September 12, 2012 14:53
Show Gist options
  • Save javiertapia/3707164 to your computer and use it in GitHub Desktop.
Save javiertapia/3707164 to your computer and use it in GitHub Desktop.
(PHP5) Extract Zip file
$fn = explode('.', $_FILES['archivo']['name']);
$ext = array_pop($fn);
if($ext == 'zip'){
$files = array();
$zip = new ZipArchive();
if( $zip->open($_FILES['archivo']['tmp_name']) ){
for($i=0; $i<$zip->numFiles; $i++){
$file = $zip->statIndex($i);
$files[] = $file['name'];
}
if(count($files)){
foreach($files as $file){
@unlink($dir . '/' . $file);
}
$mensaje = count($files) . ' archivo(s) ha(n) sido cargado(s).';
$zip->extractTo($dir);
}
$zip->close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment