Foros del Web » Programando para Internet » PHP »

Array+php+mysql

Estas en el tema de Array+php+mysql en el foro de PHP en Foros del Web. Buen dia todos, tengo el siguiente problema con los arrays, tengo el siguiente condigo Código PHP: <?php require_once( "Lineas.php" ); require_once( "fpdf.php" ); //LIBRERIA FPDF VERSION 1.7 require_once( ...
  #1 (permalink)  
Antiguo 23/03/2012, 11:48
 
Fecha de Ingreso: febrero-2009
Ubicación: mexico
Mensajes: 148
Antigüedad: 15 años, 2 meses
Puntos: 1
Array+php+mysql

Buen dia todos, tengo el siguiente problema con los arrays, tengo el siguiente condigo

Código PHP:
<?php
require_once("Lineas.php");
require_once(
"fpdf.php");//LIBRERIA FPDF VERSION 1.7
require_once("fpdi.php");//LIBRERIA FPDI

class Pdf{
    private 
$archivo;
    private 
$ruta;
    private 
$linea;
    private 
$actividad;
    private 
$subactividad;

    public function 
__construc(){
        
$this->lineas = new Lineas();//CLASE PARA AGREGAR LAS LINEAS A LA BD
    
}
    public function 
getCampo(){//DEVUELVE TODOS LOS CAMPOS
        
return $this->campo;
    }
    private function 
setCampo($campo){//ALMACENA TODOS LOS CAMPOS
        
$this->campo[] = $campo;
    }
    public function 
getServicio(){//DEVUELDE TODOS LOS SERVICIOS
        
return $this->servicio;
    }
    private function 
setServicio($servicio){//ALMACENA TODOS LOS SERVICIOS
        
$this->servicio[] = $servicio;
    }
    public function 
getLinea(){//DEVUELVE TODAS LAS LINEAS
        
return $this->linea;
    }
    private function 
setLinea($linea){//ALMACENA TODAS LAS LINEAS
        
$this->linea[] = $linea;
    }
    public function 
getActividad(){//DEVUELVE TODAS LAS ACTIVIDAD
        
return $this->actividad;
    }
    private function 
setActividad($actividad){//ALMACENA TODAS LAS ACTIVIDADES
        
$this->actividad[] = $actividad;
    }
    public function 
getSubActividad(){//DEVUELVE TODAS LAS SUBACTIVIDADES
        
return $this->subactividad;
    }
    private function 
setSubActividad($subactividad){//ALMACENA TODAS LAS SUBACTIVIDADES
        
$this->subactividad[] = $subactividad;
    }
    public function 
getArchivo(){//DEVUELVE TODOS LOS ARCHIVOS
        
return $this->archivos;
    }
    private function 
setArchivo($archivos){//ALMACENA TODOS LOS ARCHIVOS
        
$this->archivos[] = $archivos;
    }
    public function 
ContarHojas($archivo)//METODO QUE CUENTA LAS HOJAS DEL ARCHIVO PDF
    
{
        
$this->archivo $archivo;
        
$pdf = new FPDI();
        
$hojas $pdf->setSourceFile($archivo);//METODO TOMADO DE LA LIBRERIA FPDI SOLO FUNCIONA CON LOS ARCHIVOS PDF SIN OCR

        
return $hojas;
    }
    private function 
VersionDelPDF($archivo)//METODO QUE DEVUELVE LA VERSION DE ARCHIVO PDF
    
{
        
$this->archivo $archivo;
        
$pdf = new FPDI(); 
        
$pdf->setSourceFile($archivo);//LIBRERIA FPDI
        
$version $pdf->getPDFVersion();//LIBRERIA FPDI

        
return $version;
    }
    private function 
ConsultarExtension($archivo)//METODO QUE DEVUELVE LA EXTENSION DEL ARCHIVO AYUDA A DELIMITAR CUALES ARCHIVOS SON DE EXTENSION PDF
    
{
        
$this->archivo $archivo;
        
$trozos explode("."$archivo);
        
$extension end($trozos);
        
        return 
$extension;
    }
    public function 
Listar($ruta)//METODO QUE HACE EL RECORRIDO DE TODAS LAS CARPETAS Y NOS DEVUELVE LOS NOMBRES DE CARPETAS,SUBCARPETAS Y ARCHIVOS
    
{
        
$this->ruta $ruta;
        
$total = array();
        if (
is_dir($ruta)) {
            if (
$dh opendir($ruta)) {
                while ((
$file readdir($dh)) !== false) {
                    if(
$file!="." && $file!=".."){
                        if(
$this->ConsultarExtension($file)=="PDF" || $this->ConsultarExtension($file)=="pdf"){
                            
$archivo $this->CambiarExtension($file);
                            
$hojas $this->ContarHojas($ruta.$archivo);
                            
$version $this->VersionDelPDF($ruta.$archivo);

                            
$campo $this->Separar($ruta"CAMPO");
                            
$servicio $this->Separar($ruta"SERVICIO");
                            
$linea $this->Separar($ruta"LINEA");
                            
$actividad $this->Separar($ruta"ACTIVIDAD");
                            
$subactividad $this->Separar($ruta"SUBACTIVIDAD");
                            
                            
$this->setCampo($campo);
                            
$this->setServicio($servicio);
                            
$this->setLinea($linea);
                            
$this->setActividad($actividad);
                            
$this->setSubActividad($subactividad);
                            
$this->setArchivo($archivo);
                        }
                        if (
is_dir($ruta $file) && $file!="." && $file!=".."){
                            
$this->Listar($ruta $file "/");
                        }
                    }
                }
            
closedir($dh);
        }
        }else{
            echo 
"No es ruta valida";
        }
    }
    private function 
Separar($ruta,$opcion)//METODO QUE SEPARA LA RUTA DE LAS CARPETAS RECORRIDAS DE ACUERDO A LA OPCION SELECCIONADA, CAMPO,SERVICIO,LINEA,ACTIVIDAD,SUBACTIVIDAD
    
{
        
$this->ruta $ruta;
        
$this->opcion $opcion;
        
        
$total_diagonal count($var explode("/",$ruta))-7;
        
$r explode("/",$ruta);
        switch(
$opcion){
            case 
"CAMPO":
                
$valor $r[$total_diagonal+1];
            break;
            case 
"SERVICIO":
                
$valor $r[$total_diagonal+2];
            break;
            case 
"LINEA":
                
$valor $r[$total_diagonal+3];
            break;
            case 
"ACTIVIDAD":
                
$valor $r[$total_diagonal+4];
            break;
            case 
"SUBACTIVIDAD":
                
$valor $r[$total_diagonal+5];
            break;
        }
        
        return 
$valor;
    }
    private function 
CambiarExtension($archivo)//METODO QUE CAMBIA LA EXTENSION DEL ARCHIVO .PDF A .pdf YA QUE LA LIBREARIA FPDI NO ACEPTA LA EXTENSION EN MAYUSCULA
    
{
        
$this->archivo $archivo;
        
        
$var explode(".",$archivo);
        
$nombre$var[0];
        
$nombre $nombre.".pdf";
        return 
$nombre;
    }
    private function 
ComprobarCampo($campo)//METODO QUE SIRVE PARA VALIDAR NOMBRE DE LA CARPETA CAMPO, TODAVIA ESTA EN REVISION ESTE METODO PARA PODER SER UTILIZADO
    
{
        
$this->campo $campo;
        
$regEx '/^([\w]{3})+$/';
        if(
preg_match($regEx$linea)==false){
            
$resultado false;
        }else{
            
$resultado true;
        }
        return 
$resultado;
    }
    private function 
ComprobarLinea($linea)//METODO QUE SIRVE PARA VALIDAR QUE LA LINEA SEA CORRECTA Y CONTENGA UN FORMATO ESPECIFICO
    
{
        
$this->linea $linea;
        
$regEx '/^([\w]{3}[-]{1}[\w]{3}[-]{1}[\w]{3}[-]{1}[\w]{3}[-]{1}[\w]{1}[\d]{2}[-]{1}[\w]{3}[-]{1}[\w\d]{5})+$/';
        if(
preg_match($regEx$linea)==false){
            
$resultado false;
        }else{
            
$resultado true;
        }
        return 
$resultado;
    }
    private function 
ComprobarActividad($actividad)//METODO QUE SIRVE PARA VALIDAR QUE LA ACTIVIDAD SEA CORRECTA Y CONTENGA UN FORMATO ESPECIFICO
    
{
        
$this->actividad $actividad;
        
$regEx '/^([\d]{1,2})+$/';
        if(
preg_match($regEx$actividad)==false){
            
$resultado false;
        }else{
            
$resultado true;
        }
        return 
$resultado;
    }
    private function 
ComprobarSubActividad($subactividad)//METODO QUE SIRVE PARA VALIDAR QUE LA SUBACTIVIDAD SEA CORRECTA Y CONTENGA UN FORMATO ESPECIFICO
    
{
        
$this->subactividad $subactividad;
        
$regEx '/^([\d]{3,5})+$/';
        if(
preg_match($regEx$subactividad)==false){
            
$resultado false;
        }else{
            
$resultado true;
        }
        return 
$resultado;
    }
}
?>
lo utilizo de la siguiente manera

Código PHP:
<?php
require_once("clases/Pdf.php");
require_once(
"clases/Lineas.php");

$ruta ="C:\LINEAS\"; //RUTA DE LA CARPETA CONTENEDORA

$pdf = new Pdf();
$lineas = new Lineas();
$pdf->Listar($ruta);
$campo = $pdf->getCampo();//DEVUELVE EN UN ARRAY LOS NOMBRES DE LA CARPETAS LOS CAMPOS
$servicio = $pdf->getServicio();//DEVUELVE EN UN ARRAY LOS NOMBRES DE LA CARPETAS LOS SERVICIOS
$linea = $pdf->getLinea();//DEVUELVE EN UN ARRAY LOS NOMBRES DE LA CARPETAS LOS LINEA
$actividad = $pdf->getActividad();//DEVUELVE EN UN ARRAY LOS NOMBRES DE LA CARPETAS LOS ACTIVIDAD
$subactividad = $pdf->getSubActividad();//DEVUELVE EN UN ARRAY LOS NOMBRES DE LA CARPETAS LOS SUBACTIVIDAD
$archivo = $pdf->getArchivo();//DEVUELVE EN UN ARRAY LOS NOMBRES DE LA CARPETAS LOS ARCHIVO

$total_campo = count($campo);//CUENTA EL NUMERO DE ELEMENTOS DEL ARRAY
$total_servicio = count($servicio);//CUENTA EL NUMERO DE ELEMENTOS DEL ARRAY
$total_linea = count($linea);//CUENTA EL NUMERO DE ELEMENTOS DEL ARRAY
$total_actividad = count($actividad);//CUENTA EL NUMERO DE ELEMENTOS DEL ARRAY
$total_subactividad = count($subactividad);//CUENTA EL NUMERO DE ELEMENTOS DEL ARRAY
$total_archivo = count($archivo);//CUENTA EL NUMERO DE ELEMENTOS DEL ARRAY
?>
ahora quiero que toda esa info se guarde en una bd con la siguiente estructura



Al momento de ejecutar el script el resultado es el siguiente quiero que me inserte la informacion de las carpetas y archivos en la BD, por ejemplo teniendo la siguiente ruta:

$ruta="C:\LINEAS\";

el resultado al momento de ejecutar el escript es el siguiente

CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O1.PDF
CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O2.PDF
CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O3.PDF
CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O4.PDF

lo que yo quiero es insertar los nombres de la carpeta CAMPO en la tabla campo, y asi con las demas pero no se como hacerlo, alguien podria ayudarme

  #2 (permalink)  
Antiguo 23/03/2012, 13:40
Avatar de informacionsys  
Fecha de Ingreso: mayo-2011
Ubicación: Bogota D.C
Mensajes: 793
Antigüedad: 13 años
Puntos: 76
Respuesta: Array+php+mysql

hola

que quieres guardar exactamente en la base de datos, quieres guardar en el campo

estas rutas :


CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O1.PDF
CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O2.PDF
CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O3.PDF
CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O4.PDF

o explicate un poco mejor
  #3 (permalink)  
Antiguo 23/03/2012, 18:44
 
Fecha de Ingreso: febrero-2009
Ubicación: mexico
Mensajes: 148
Antigüedad: 15 años, 2 meses
Puntos: 1
Pregunta Respuesta: Array+php+mysql

efectivamente quiero guardar estos datos

CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O1.PDF
CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O2.PDF
CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O3.PDF
CAMPO\SERVICIO\LINEA\ACTIVIDAD\SUBACTIVIDAD\ARCHIV O4.PDF

en su respectiva tabla, en pocas palabras con las rutas de arriba deberia quedar asi en cada tabla.

En la tabla campo debe ir el nombre de la carpeta CAMPO(que puede ser cualquier otro nombre).
En la tabla servicio debe guardar el nombre de la carpeta SERVICIO(que puede ser cualquier otro nombre) con el id_campo insertado anteriormente.
En la tabla linea debe guardar el nombre de la carpeta LINEA(que puede ser cualquier otro nombre) con el id_servicio insertado anteriormente.
Con respecto a la tabla actividad no hay problema ya que puedo hacer una consulta y comparar la actividad contenida en dicha tabla al igual que con la tabla sub_actividad.
En la tabla archivo por supuesto debe ir el nombre del archivo y la cantidad de hojas, el id_sub_actividad de la tabla sub Actividad correspondiente de acuerdo a la estructura de las carpetas, el id_linea de la linea d acuerdo a la estructura de las carpetas al final por ejemplo quedaria asi o deberia quedar asi:

//RUTAS DE LOS ARCHIVOS
C:\LINEAS\CAPARROSO\LDD\PEP-SUR-SML-LUN-B01-LDD-L0195\1\1.1\ARCHIVO1.PDF
C:\LINEAS\CAPARROSO\OLD\PEP-SUR-SML-LUN-B01-LDD-L0195\1\1.1\ARCHIVO1.PDF
C:\LINEAS\CAPARROSO\GLD\PEP-SUR-SML-LUN-B01-LDD-L0195\1\1.1\ARCHIVO1.PDF
C:\LINEAS\CAPARROSO\GDO\PEP-SUR-SML-LUN-B01-LDD-L0195\1\1.1\ARCHIVO1.PDF

LA VARIABLE RUTA SOLO SE INSERTA LA RUTA DE ESTA MANERA C:\LINEAS\ PARA QUE SE PUEDA RECORRER TODAS LAS SUBCARPETAS Y ARCHIVOS CONTENIDAS DENTRO DE ELLA, SIGUIENDO CON EL TEMA EN LA BASE DE DATOS DEBERIA TENER INSERTADO:

campo(1,CAPARROSO);
servicio(1,1,LDD);
linea(1,1,PEP-SUR-SML-LUN-B01-LDD-L0195);
actividad(1,1);
sub_actividad(1,1,1.1);
archivos(1,1,1,1,4,ARCHIVO1.PDF,2010-01-01,123456,10,ninguno);

LO ANTERIOR PARA EL PRIMER ARCHIVO Y ASÍ SUCESIVAMENTE PERO EL DETALLE ES QUE DESPUES SE INSERTAN LOS CAMPOS EN VEZ DE INSERTAME LOS SERVICIOS QUE DEBEN DE SER ME INSERT EL SERVICIO PERO INDEFINIDAMENTE, ...ESPERO HABERME EXPLICADO CORRECTAMENTE-

Etiquetas: arreglos, mysql, poo, tabla
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:14.