elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recopilación Tutoriales y Manuales Hacking, Seguridad, Privacidad, Hardware, etc


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  Ordenar galería de imagenes por fecha.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Ordenar galería de imagenes por fecha.  (Leído 2,874 veces)
Joystickoso

Desconectado Desconectado

Mensajes: 44



Ver Perfil
Ordenar galería de imagenes por fecha.
« en: 21 Abril 2009, 22:34 pm »

Hola. Tengo hecha una galeria de fotos en php con partes de una galeria prefabricada que me descargué. Consta de dos partes, una es para subir las imagenes y crear los thumbs en una carpeta para la galeria y la otra abre la carpeta donde están y la muestra en una tabla.
Mi problema es que muestra las imagenes en dicha tabla pero sin ningun orden aparente, lo he mirado y no es ni por tamaño ni fecha ni nombre.
Son dos archivos index.php y gallerybuilder.php. (pongo solo lo importante)
Index.php
Código:
<?php
// el archivo empieza por

 $default = "";
 include("galleryBuilder.php");
?>
// y el codigo de la tabla donde aparecen las imagenes
<table align="center">
                <?php createGallery("Upload/pics/" . $a, "Upload/pics/" . $a . "thumbs/", 120, 80, 5, FALSE); ?>
              </table>
Y el Gallerybuilder.php
Código:
<?php
if($_GET["a"] != "")
{
 $a = $_GET["a"] . "/";
}
else
{
 $a = $default . "/";
}
// This is a very basic way of determining whether to insert
// an extra trailing slash or not


function createGallery($gF, $tF, $tW, $tH, $nR, $nW)
{
 // $gF is the path to the folder that contains the images
 //     example: "gallery/"

 // $tF is the path to the folder that contains the thumbnails of the images
 //     example: "gallery/thumbs/"

 // $tW is the desired width of the thumbnails
 //     example: 120

 // $tH is the maximum desired height of the thumbnails
 //     example: 80

 // $nR is the desired number of images in each row of the table
 //     example: 8

 // $nW is a boolean value. If set to TRUE, opens full sizes in new window
 //     example: FALSE


 echo " <tr>\n";

 buildThumbs($gF, $tF, $tW, $tH);
 // call to another function to generate the thumbs

 $open = opendir($gF);
 // open the directory to the gallery folder

 $i = 1;
 $j = 1;
 // we use $i and $j to loop alternating table cells and the number of cells
 // per row
 while(FALSE !== ($fileName = readdir($open)))
 {
  $info = pathinfo($gF . $fileName);
  // get info for the filename
  if(strtolower($info["extension"]) == "jpe" || strtolower($info["extension"]) == "jpeg" || strtolower($info["extension"]) == "jpg" || strtolower($info["extension"]) == "gif" || strtolower($info["extension"]) == "png")
  {
  // this case-insensitively checks for all possible JPEG, GIF, and PNG extensions and only
  // returns files that meet these conditions
   echo "  <td width=\"" . $tW . "\" height=\"" . $tH . "\" class=\"galleryCell";
   if($i == 1)
   {
    // if $i is 1
    echo "1";
    $i = 2;
   }
   else
   {
    echo "2";
    $i = 1;
   }
   echo "\"><a";
   if($nW == TRUE)
   {
    echo " target=\"_blank\"";
   }
   echo " href=\"" . $gF . $fileName . "\" title=\"" . $fileName . "\"><img class=\"galleryImage\" src=\"" . $tF . $fileName .  "\" border=\"0\"></a></td>\n";
   if($j == $nR)
   {
    // if $j is the number or cells per row...
    echo " </tr>\n <tr>\n";
    $j = 1;
   }
   else
   {
    $j++;
   }
  }
 }
 closedir($open);
 // close the directory
 echo " </tr>\n";
}






function buildThumbs($gF, $tF, $tW, $tH)
{
 // $gF is the path to the folder that contains the images
 //     example: "gallery/"

 // $tF is the path to the folder that contains the thumbnails of the images
 //     example: "gallery/thumbs/"

 // $tW is the desired width of the thumbnails
 //     example: 120

 // $tH is the maximum desired height of the thumbnails
 //     example: 80

 $open = opendir($gF);
 // open the directory to the gallery folder
 while(FALSE !== ($fileName = readdir($open)))
 {
  // loop throught the entire directory
  if(!file_exists($tF . $fileName))
  {
   // there is NOT already a thumbnail with the same name, so let's create one!
   $info = pathinfo($gF . $fileName);
   // get file info for each file
   if(strtolower($info["extension"]) == "jpe" || strtolower($info["extension"]) == "jpeg" || strtolower($info["extension"]) == "jpg" || strtolower($info["extension"]) == "gif" || strtolower($info["extension"]) == "png")
   {
    // this really long line asks if the lowercase version of the extension ends in each JPEG format (jpe, jpeg, jpg), a GIF format (gif), or a PNG format (png), all of our valid image types
    if(strtolower($info["extension"]) == "jpe" || strtolower($info["extension"]) == "jpeg" || strtolower($info["extension"]) == "jpg")
    {
     // this narrows it down--the image must be a JPEG
     $thumbnail = imagecreatefromjpeg($gF . $fileName);
    }
    if(strtolower($info["extension"]) == "gif")
    {
     // it must be a GIF
     $thumbnail = imagecreatefromgif($gF . $fileName);
    }
    if(strtolower($info["extension"]) == "png")
    {
     // create a PNG
     $thumbnail = imagecreatefrompng($gF . $fileName);
    }
    $oWidth    = imagesx($thumbnail);
    // original width
    $oHeight   = imagesy($thumbnail);
    // original height
    $tWidth    = $tW;
    // the new thumbnail will have the specified width
    $tHeight   = floor($oHeight * ($tWidth / $oWidth));
    // calculate the thumbnail height by multiplying the original height by the width ratio
    if($tHeight > $tH)
    {
     // if the image is still too tall...
     $tHeight  = $tH;
     // set the height to the max height
     $tWidth   = floor($oWidth * ($tHeight / $oHeight));
     // calculate the thumnail width by multiplying the original width by the height ratio
    }
    $tempImage = imagecreatetruecolor($tWidth, $tHeight);
    // create a temporary image (it's blank right now)

    imagecopyresized($tempImage, $thumbnail, 0, 0, 0, 0, $tWidth, $tHeight, $oWidth, $oHeight);
    // copy and resize the full-size image into a thumbnail - see PHP.net's imagecopyresized() function for details

    if(strtolower($info["extension"]) == "jpe" || strtolower($info["extension"]) == "jpeg" || strtolower($info["extension"]) == "jpg")
    {
     // save a JPG thumbnail!
     $thumbnail = imagejpeg($tempImage, $tF . $fileName);
    }
    if(strtolower($info["extension"]) == "gif")
    {
     // save a GIF thumbnail!
     $thumbnail = imagegif($tempImage, $tF . $fileName);
    }
    if(strtolower($info["extension"]) == "png")
    {
     // save a PNG thumbnail!
     $thumbnail = imagepng($tempImage, $tF . $fileName);
    }
   }
  }
 }
 closedir($open);
 // close the directory
}






function listAlbums($gF, $aS, $dF)
{
 // $gF is the path to the folder that contains the subfolders
 //     example: "gallery/"

 // $aS is the separator between each album title
 //     example: " &bull; "

 // $dF is the default folder that we wish to exclude from the list
 //     example: "default_gallery"

 $open = opendir($gF);
 // open the directory to the gallery folder

 $i = 1;
 $toReturn = "";
 // we use $i to loop through the count and $toReturn to come
 // up with a full album list to echo later
 while(FALSE !== ($fileName = readdir($open)))
 {
  if(is_dir($gF . $fileName) && $fileName != "." && $fileName != ".." && $fileName != $dF)
  {
   // if the file is actually a directory... ("." and ".." are not directories) and NOT the default
   $displayName = str_replace("_", " ", $fileName);
   // change all underscores to spaces in the display name
   $displayName = ucwords($displayName);
   // capitalize the first letter of each word in the display name
   $toReturn = $toReturn . "<a href=\"?a=" . $fileName . "\">" . $displayName . "</a>" . $aS;
   // add the album name, and add a separator
  }
 }
 $aS_length = strlen($aS);
 // here we figure out how many characters $aS is
 $aS_length = $aS_length * -1;
 // get the negative number
 echo substr_replace($toReturn, "", $aS_length);
 // this is a messy but understandable way to remove the last
 // album separator from the list

}
?>
Lo que quiero es que "opendir" ordene las imagenes por la fecha en la que han subido las imagenes. Como lo hago?
Gracias de antemano.


« Última modificación: 21 Abril 2009, 22:36 pm por Joystickoso » En línea

#!drvy
Moderador
***
Desconectado Desconectado

Mensajes: 5.850



Ver Perfil WWW
Re: Ordenar galería de imagenes por fecha.
« Respuesta #1 en: 21 Abril 2009, 23:41 pm »

Lo que te sugiero yo es que lo hagas pasar por una base de datos....te vas a ahorrar muchas molestias y tendrás todo mas organizado..



Saludos


En línea

Joystickoso

Desconectado Desconectado

Mensajes: 44



Ver Perfil
Re: Ordenar galería de imagenes por fecha.
« Respuesta #2 en: 24 Abril 2009, 02:20 am »

Lo intentare a ver que tal, que acabo de empezar con estas cosas y aun ando un poco pez. Gracias.
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Ordenar archivos de un directorio por fecha
PHP
177600531 2 6,203 Último mensaje 12 Febrero 2013, 12:20 pm
por 177600531
Fecha de lanzamiento y nuevas imágenes de DOOM
Noticias
wolfbcn 0 849 Último mensaje 7 Enero 2016, 18:48 pm
por wolfbcn
SQL: quitar id's repetidos y ordenar por fecha
Bases de Datos
JonaLamper 1 2,677 Último mensaje 15 Septiembre 2016, 19:30 pm
por ivancea96
ordenar por fecha mas antigua
Bases de Datos
xlasekx 2 1,635 Último mensaje 1 Agosto 2019, 19:49 pm
por crisoof
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines