Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created May 28, 2019 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/7e4c51f7e61dfcfdfb1c7621f2a59ced to your computer and use it in GitHub Desktop.
Save parzibyte/7e4c51f7e61dfcfdfb1c7621f2a59ced to your computer and use it in GitHub Desktop.
<?php
/**
* Trabajando con archivos ZIP en PHP
* Ejemplo 3: agregar archivos a partir de patrón GLOB
*
* @author parzibyte
*/
$zip = new ZipArchive();
// Ruta absoluta
$nombreArchivoZip = __DIR__ . "/3-glob.zip";
if (!$zip->open($nombreArchivoZip, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
exit("Error abriendo ZIP en $nombreArchivoZip");
}
// Si no hubo problemas, continuamos
$zip->addGlob("*.go");
$zip->addGlob("*.log");
$zip->addGlob("*.xlsx");
$zip->addGlob("*.js");
// Otros ejemplos: $zip->addGlob("./imagenes/*.png");
// Otros ejemplos: $zip->addGlob("*.php");
// Otros ejemplos: $zip->addGlob("*.*");
// No olvides cerrar el archivo
$resultado = $zip->close();
if ($resultado) {
echo "Archivo creado";
} else {
echo "Error creando archivo";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment