Ver Mensaje Individual
  #8 (permalink)  
Antiguo 25/09/2015, 16:39
Kaeper
 
Fecha de Ingreso: septiembre-2015
Ubicación: Colima
Mensajes: 6
Antigüedad: 8 años, 7 meses
Puntos: 0
Respuesta: Crear ZIP en php

Esta solo es una función del controlador, faltó un poco de código pero es irrelevante (consultas) al problema.

$aux=null;
unlink('juke4.zip');
//Creando el archivo zip
$zip = new ZipArchive();
$filename = './juke4.zip';
if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
exit("cannot open <$filename>\n");
}
else{
foreach ($result as $key ) {
foreach ($key as $keyy ) {
//Obtener los xml y pdf - CFDI
foreach ($xmlGastos as $keyXml){
foreach ($keyXml as $keyyXml){
if($keyyXml->eCodComprobante==$keyy->eCodComprobante){
if($aux==null){
$aux=(string)$keyyXml->Pdf;
$zip->addFile("".$aux,$keyyXml->UUID.".pdf");
$aux=(string)$keyyXml->ArchivoXml;
$zip->addFile("".$aux,$keyyXml->UUID.".xml");
$aux=$keyyXml->UUID;
}

elseif($aux!=$keyyXml->UUID){
$aux=(string)$keyyXml->Pdf;
$zip->addFile("".$aux,$keyyXml->UUID.".pdf");
$aux=(string)$keyyXml->ArchivoXml;
$zip->addFile("".$aux,$keyyXml->UUID.".xml");
$aux=$keyyXml->UUID;
}
}

}
}
//Obtener imagenes y pdf - no deducible
foreach ($gastos as $keyGas){
foreach ($keyGas as $keyyGas){
if($keyyGas->eCodComprobante==$keyy->eCodComprobante){
$aux=(string)$keyyGas->Imagen;
$ext=substr($aux, -3);
$zip->addFile("".$aux,$keyyGas->eCodRelacion.$keyyGas->eCodComprobante.".".$ext);
}

}
}
}
}
}
//Llave del foreach
$zip->close();
ob_end_clean();
//then send the headers to foce download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=archivos.zip");
header("Pragma: no-cache");
header("Expires: 0");
readfile("./juke4.zip");
}//Llave del if

$result=$this->mcomprobante->getAprobados();
$data['result']=$result;
$tipoCompania=$this->mcomprobante->getCatCompanias();
$data['tipoCompania']=$tipoCompania;
$this->load->view('GMI/11/vista11',$data);
}//Llave de la funcion