Ver Mensaje Individual
  #5 (permalink)  
Antiguo 24/08/2010, 09:03
alexisfch
 
Fecha de Ingreso: septiembre-2007
Mensajes: 150
Antigüedad: 16 años, 7 meses
Puntos: 1
Respuesta: array segun file_exists

Cita:
Iniciado por maycolalvarez Ver Mensaje
al final obtienes lo que necesitas
mira lo hice como mencionaste pero no se logra construir el array correctamente
te muestro el code.

Código PHP:
if(file_exists("tmp/".$_GET['products_id']."conlogo.zip")) {  
}else {
include(
"createzipconlogo.php");
$imagen1 "images/"$product_info['products_image_med'];
$imagen2 "images/"$product_info['products_image_xl_1'];
$imagen3 "images/"$product_info['products_image_xl_2'];
$imagen4 "images/"$product_info['products_image_xl_3'];
$imagen5 "images/"$product_info['products_image_xl_4'];
$imagen6 "images/"$product_info['products_image_xl_5'];
$imagen7 "images/"$product_info['products_image_xl_6'];

//borrando los espacios
$imagen1mod=str_replace(' ',"%20",$imagen1);
$imagen2mod=str_replace(' ',"%20",$imagen2);
$imagen3mod=str_replace(' ',"%20",$imagen3);
$imagen4mod=str_replace(' ',"%20",$imagen4);
$imagen5mod=str_replace(' ',"%20",$imagen5);
$imagen6mod=str_replace(' ',"%20",$imagen6);
$imagen7mod=str_replace(' ',"%20",$imagen7);

$contlogo=array(
"1.jpg" => $imagen1mod,
"2.jpg" => $imagen2mod
"3.jpg" => $imagen3mod,
"4.jpg" => $imagen4mod,
"5.jpg" => $imagen5mod
"6.jpg" => $imagen6mod,
"7.jpg" => $imagen7mod,
);

foreach(
$contlogo as $key => $value){
    if(
file_exists($value)){
        
$contlogo[$key] = file_get_contents($value);
    }else{
        unset(
$contlogo[$key]);
    }
}
//construyendo el zip con solo los archivos que existen
createziplogo($contlogo,"tmp/".$_GET["products_id"]."conlogo.zip") or die("Error: al construir el ZIP.");

el createzipconlogo.php
Código PHP:
function createziplogo($struct,$namezip=0)
{     
$ZipData = array(); 
    
$Dircont = array(); 
    
$DirFile = array();
    
$offseto 0;        
    while(list(
$file,$data)=each($struct))
    {    
$filestr_replace("\\""/"$file);  
        
$dir=explode("/",$file);
        for(
$i=0$i<sizeof($dir); $i++)if($dir[$i]=="")unset($dir[$i]);                    
        
$num=count($dir); //Total de niveles
        
$ele=0;            //Nivel actual
        
$dirname="";      //Nombre archivo o directorio
        
while(list($idx,$val)=each($dir))
        {    
$ty=(++$ele)==$num?true:false;
            
$ty=trim($data)!=""?$ty:false;//Compruebar si el ultimo elemento es directorio o archivo
            
$dirname.=$val.($ty?"":"/");
            if(isset(
$DirFile[$dirname]))continue; else $DirFile[$dirname]=true;            
            
$gzdata="";                
            if(
$ty)
            {    
$unziplen=strlen($data);  
                
$czip=crc32($data);  
                
$gzdata=gzcompress($data);  
                
$gzdata=substr(substr($gzdata,0,strlen($gzdata)-4),2); 
                
$cziplen=strlen($gzdata);  
            }                        
            
$ZipData[]="\x50\x4b\x03\x04".($ty?"\x14":"\x0a")."\x00\x00\x00".($ty?"\x08":"\x00")."\x00\x00\x00\x00\x00".
                       
pack("V",$ty?$czip:0).pack("V",$ty?$cziplen:0).pack("V",$ty?$unziplen:0).pack("v",strlen($dirname)). 
                       
pack("v",0).$dirname.$gzdata.pack("V",$ty?$czip:0).pack("V",$ty?$cziplen:0).pack("V",$ty?$unziplen:0);
            
$Dircont[]="\x50\x4b\x01\x02\x00\x00".($ty?"\x14":"\x0a")."\x00\x00\x00".($ty?"\x08":"\x00")."\x00\x00\x00\x00\x00".
                       
pack("V",$ty?$czip:0).pack("V",$ty?$cziplen:0).pack("V",$ty?$unziplen:0).pack("v",strlen($dirname)). 
                       
pack("v").pack("v",0).pack("v",0).pack("v",0).pack("V",$ty?32:16).pack("V",$offseto).$dirname;          
            
$offseto=strlen(implode("",$ZipData));            
        }
//Fin While dir        
    
}//Fin While archivos
    
$data implode("",$ZipData);  
    
$cdir implode("",$Dircont);      
    
$data=$data.$cdir."\x50\x4b\x05\x06\x00\x00\x00\x00".pack("v",sizeof($Dircont)).pack("v",sizeof($Dircont)).pack("V",strlen($cdir)).pack("V",strlen($data))."\x00\x00";
    if(
$namezip)//Construir el archivo
    
{    if(($fp=fopen($namezip,"wb")))
           {    
fwrite($fp,$data);
            
fclose ($fp);
            return 
true;
        }else return 
false;
    }else return 
$data;