Foros del Web » Programando para Internet » PHP »

visor de imagenes por carpeta...¿?

Estas en el tema de visor de imagenes por carpeta...¿? en el foro de PHP en Foros del Web. Hola, necesito hacer un visor de fotos de la siguiente manera... yo poner el archivo index.php(visor de imagenes) en root y indicarle que carpeta ver, ...
  #1 (permalink)  
Antiguo 14/09/2006, 12:51
 
Fecha de Ingreso: febrero-2005
Mensajes: 183
Antigüedad: 19 años, 2 meses
Puntos: 0
Exclamación visor de imagenes por carpeta...¿?

Hola, necesito hacer un visor de fotos de la siguiente manera...
yo poner el archivo index.php(visor de imagenes) en root y indicarle que carpeta ver, por ejemplo:
www.miqeb.com.ar/index.php?=ImgCarpeta2
Se entiende?
Un visor de imagenes pero que yo le indique que carpeta leer de manera dinamica, para q? para no tener que hacer un html por cada trabajo que tenga que mostrar en un porfolio.
Desde ya muchas gracias.
  #2 (permalink)  
Antiguo 14/09/2006, 14:04
Avatar de Gurrutello  
Fecha de Ingreso: enero-2002
Ubicación: Ontario,Toronto [Canada]
Mensajes: 2.017
Antigüedad: 22 años, 3 meses
Puntos: 6
Hola
lo he hecho de prisa y corriendo pero seria lago asi
Código PHP:
<?
//www.miqeb.com.ar/index.php?=ImgCarpeta2
//www.miqeb.com.ar/index.php?valor_carpeta=ImgCarpeta2
$mi_directorio $_SERVER['DOCUMENT_ROOT'] ."/".$_REQUEST['valor_carpeta']."/";
if (
file_exists($mi_directorio)) { 
  
$carpetas=opendir($mi_directorio);
  while (
$archivos_carpeta readdir($carpetas)) {
      
$nombres[] = $archivos_carpeta;
    echo 
"<img src='".$archivos_carpeta."' border="0">";

  }
  
closedir($carpetas);
  } else { 
 echo 
"NO ENCONTRADO"
}
?>
espero que te sirva o al menos de una idea
saludos
__________________
Un Saludo
www.tutores.org
Asp | Php | Javascript | Perl | Coldfusion | Flash | +- 2000 codigos
  #3 (permalink)  
Antiguo 14/09/2006, 15:22
Avatar de sordo77  
Fecha de Ingreso: noviembre-2002
Ubicación: Rosario
Mensajes: 70
Antigüedad: 21 años, 4 meses
Puntos: 0
Thumbnail de imágenes

Requiere GD 2.0.1 or superior.

Para probarlo localmente pone:
http://localhost/portfolio/index.php?dir=misfotos

Espero que te sirva
Se puede mejorar agregándole paginación.

Cita:
index.php
Código PHP:
<html>
<head>
<title>Portfolio</title>
</head>
<body>
<?php
require 'DirectoryItems.php';
$directory $_GET["dir"];
$di =& new DirectoryItems($directory);
$di->imagesOnly();
$di->naturalCaseInsensitiveOrder();
echo 
"<div style=\"text-align:center;\">";
echo 
"Haga click sobre el título para ver la imagen en tamaño completo.<br />";
$filearray $di->getFileArray();
$path "";
$size 100;    // Tamaño thumbnail
foreach ($filearray as $key => $value){
  
$path "$directory/".$key;
  echo 
"<img src=\"getthumb.php?path=$path&amp;size=$size\" ".
    
"style=\"border:1px solid black;margin-top:20px;\" ".
    
"alt= \"$value\" /><br />\n";
  echo 
"<a href=\"$path\" target=\"_blank\" >";
  echo 
"Título: $value</a> <br />\n";
}
echo 
"</div><br />";
?>
</body>
</html>
Cita:
DirectoryItems.php
Código PHP:
<?php
class DirectoryItems{
    var 
$filearray = array();
    var 
$replacechar;
    var 
$directory;

   function 
DirectoryItems($directory$replacechar "_"){
        
$this->directory $directory;
        
$this->replacechar $replacechar;
        
$d "";
      if(
is_dir($directory)){
          
$d opendir($directory) or die("Falló al abrir directorio.");
          while(
false !== ($f readdir($d))){
            if(
is_file("$directory/$f")){
                    
$title $this->createTitle($f);
                    
$this->filearray[$f] = $title;
            }
          }
            
closedir($d);
        }else{
            die(
"Debe pasar un directorio.");
        }
    }

     function 
__destruct(){
        unset(
$this->filearray);
    }

     function 
getDirectoryName(){
        return 
$this->directory;
    }

     function 
indexOrder(){
        
sort($this->filearray);
    }

     function 
naturalCaseInsensitiveOrder(){
        
natcasesort($this->filearray);
    }

     function 
checkAllImages(){
        
$bln true;
        
$extension "";
        
$types = array("jpg""jpeg""gif""png");
        foreach (
$this->filearray as $key => $value){
            
$extension substr($key,(strpos($key".")+1));
            
$extension strtolower($extension);
            if(!
in_array($extension$types)){
                
$bln false;
                break;
            }
        }
        return 
$bln;
    }

     function 
checkAllSpecificType($extension){
        
$extension strtolower($extension);
        
$bln true;
        
$ext "";
        foreach (
$this->filearray as $key => $value){
            
$ext substr($key,(strpos($key".")+1));
            
$ext strtolower($ext);
            if(
$extension != $ext){
                
$bln=false;
                break;
            }
        }
        return 
$bln;
    }

     function 
getCount(){
        return 
count($this->filearray);
    }

     function 
getFileArray(){
        return 
$this->filearray;
    }

     function 
getFileArraySlice($start$length){
        return 
array_slice($this->filearray$start$length);
    }

     function 
filter($extension){
        
$extension strtolower($extension);
        foreach (
$this->filearray as $key => $value){
            
$ext substr($key,(strpos($key".") + 1));
            
$ext strtolower($ext);
            if(
$ext != $extension){
                unset(
$this->filearray[$key]);
            }
        }
    }

     function 
imagesOnly(){
        
$extension "";
        
$types = array("jpg""jpeg""gif""png");
        foreach (
$this->filearray as $key => $value){
            
$extension substr($key,(strpos($key".") + 1));
            
$extension strtolower($extension);
            if(!
in_array($extension$types)){
                unset(
$this->filearray[$key]);
            }
        }
    }

     function 
removeFilter(){
        unset(
$this->filearray);
        
$d "";
        
$d opendir($this->directory) or die("Falló al abrir directorio.");
        while(
false!==($f=readdir($d))){
          if(
is_file("$this->directory/$f")){
                
$title $this->createTitle($f);
                
$this->filearray[$f] = $title;
          }
        }
        
closedir($d);
    }

    function 
createTitle($title){
        
$title substr($title,0,strrpos($title"."));
        
$title str_replace($this->replacechar" "$title);
        return 
$title;
    }
}
?>
Cita:
Thumbnailmage.php
Código PHP:
<?php
class ThumbnailImage{
    var 
$image;
    var 
$maxdimension;
    var 
$quality=100;
    var 
$fileextension;
    var 
$mimetype;
    var 
$imageproperties;
    var 
$types= array("jpg""jpeg""gif""png");

    function 
ThumbnailImage($path$maxdimension=100){
        
$this->maxdimension=$maxdimension;
        
is_file($path) or die ("Archivo: $path no existe.");
        
$extension=substr($path,(strpos($path".")+1));
        
$extensionstrtolower($extension);
        
in_array($extension$this->types) or die ("Tipo de archivo incorrector.");
        
$this->fileextension=$extension;
        
$this->setMimeType($extension);
        
$this->imageproperties GetImageSize($path);
        if(
$extension=="jpeg" || $extension=="jpg"){
            
$this->image=imagecreatefromJPEG($path);
        }elseif(
$extension=="gif"){
            
$this->image=imagecreatefromGIF($path);
        }elseif(
$extension=="png"){
            
$this->image=imagecreatefromPNG($path);
        }else{
            die(
"No se pudo crear la images.");
        }
        
$this->createThumb();
    }

    function 
getImage(){
        
header("Content-type: $this->mimetype");
        if(
$this->fileextension=="jpeg" || $this->fileextension=="jpg"){
            
imagejpeg($this->image,"",$this->quality);
        }elseif(
$this->fileextension=="gif"){
            
$image=imagegif($this->image);
        }elseif(
$this->fileextension=="png"){
            
$image=imagepng($this->image);
        }else{
            die(
"No se pudo crear la imagen.");
        }
    }

    function 
getMimeType(){
        return 
$this->mimetype;
    }

    function 
getQuality(){
        if(
$this->fileextension=="jpeg" || $this->fileextension=="jpg"){
            
$quality=$this->quality;
        }else{
            
$quality=-1;
        }
        return 
quality;
    }

    function 
setQuality($quality){
        if(
$quality 100 || $quality 1)
            
$quality=75;
        if(
$this->mimetype=="image/jpeg"){
            
$this->quality=$quality;
        }
    }

    function 
destroy(){
        
imagedestroy($this->image);
    }

    function 
setMimeType($extension){
        if(
$extension=="jpeg" || $extension=="jpg"){
            
$this->mimetype="image/jpeg";
        }elseif(
$extension=="png"){
            
$this->mimetype="image/png";
        }elseif(
$extension=="gif"){
            
$this->mimetype="image/gif";
        }else{
            die (
"Tipo no reconocido.");
        }
    }

    function 
createThumb(){
        
$srcW=$this->imageproperties[0];
        
$srcH=$this->imageproperties[1];
        if(
$srcW>$this->maxdimension || $srcH>$this->maxdimension){
            
$reduction=$this->calculateReduction($srcW,$srcH);

              
$desW=round($srcW/$reduction);
              
$desH=round($srcH/$reduction);
            if(
$this->mimetype=="image/gif"){
                
$copy=imagecreate($desW$desH);
            }else{
                
$copy=imagecreatetruecolor($desW$desH);
            }
            
imagecopyresampled($copy,$this->image,0,0,0,0,$desW$desH$srcW$srcH)
                 or die (
"Falló al copiar imagen.");
            
imagedestroy($this->image);
            
$this->image=$copy;
        }
    }

    function 
calculateReduction($srcW$srcH){
          if(
$srcW<$srcH){
              
$reduction=$srcH/$this->maxdimension;
          }else{
              
$reduction=$srcW/$this->maxdimension;
          }
        return 
$reduction;
    }
}
?>
Cita:
getthumb.php
Código PHP:
<?php
require 'ThumbnailImage.php';
$path = @$_GET["path"];
$maxsize = @$_GET["size"];
if(!isset(
$maxsize)){
    
$maxsize=100;
}
if(isset(
$path)){
  
$thumb =& new ThumbNailImage($path100);
  
$thumb->getImage();
}
?>
__________________
"Los únicos subespacios propios de R3 son los conjuntos de vectores que están en una recta o un plano que pasa por el origen."
  #4 (permalink)  
Antiguo 14/09/2006, 19:56
 
Fecha de Ingreso: febrero-2005
Mensajes: 183
Antigüedad: 19 años, 2 meses
Puntos: 0
Hey! muchisimas gracias, ambos estan perfectos, mil gracias!!!
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 23:46.