Tema: HTML vs PHP
Ver Mensaje Individual
  #6 (permalink)  
Antiguo 20/07/2011, 12:30
Avatar de 8000
8000
 
Fecha de Ingreso: julio-2011
Mensajes: 3
Antigüedad: 12 años, 9 meses
Puntos: 0
Respuesta: HTML vs PHP

Muy buenas, gracias por las respuetas,

Para solucionar lo de poner en "index.html" la página en PHP, voy a utilizar "iframe"

Código HTML:
Ver original
  1. <iframe src="pagequequierasponer" width="500" height="400" align="center" scrolling="yes" frameborder="yes"></iframe>

En scrolling y frameborder cambiaré y pondré "NO", así se verá sin marcos ni cosas raras y parecerá parte de la web.

Por otro lado, el problema de mostrar la imagen más reciente de una carpeta. He encontrado estos dos códigos:

Código 1:

Código PHP:
Ver original
  1. <?php
  2. $ruta = "uploads/original/"; // Indicar ruta
  3. $filehandle = opendir($ruta); // Abrir archivos
  4. while ($file = readdir($filehandle)) {
  5.         if ($file != "." && $file != "..") {
  6.                 $tamanyo = GetImageSize($ruta . $file);
  7.                 echo "<p><img src='$ruta$file' $tamanyo[3]><br></p>\n";
  8.         }
  9. }
  10. closedir($filehandle); // Fin lectura archivos
  11. ?>

Muestra todas imagenes de la carpeta y

Código 2:

Código PHP:
Ver original
  1. /*
  2.     In this file we are scanning the image folders and
  3.     returning a JSON object with file names. It is used
  4.     by jQuery to display the images on the main page:
  5. */
  6.  
  7. // The standard header for json data:
  8. header('Content-type: application/json');
  9.  
  10. $perPage = 24;
  11.  
  12. // Scanning the thumbnail folder for JPG images:
  13. $g = glob('uploads/thumbs/*.jpg');
  14.  
  15. if(!$g){
  16.     $g = array();
  17. }
  18.  
  19. $names = array();
  20. $modified = array();
  21.  
  22. // We loop though the file names returned by glob,
  23. // and we populate a second file with modifed timestamps.
  24.  
  25. for($i=0,$z=count($g);$i<$z;$i++){
  26.     $path = explode('/',$g[$i]);
  27.     $names[$i] = array_pop($path);
  28.  
  29.     $modified[$i] = filemtime($g[$i]);
  30. }
  31.  
  32. // Multisort will sort the array with the filenames
  33. // according to their timestamps, given in $modified:
  34.  
  35. array_multisort($modified,SORT_DESC,$names);
  36.  
  37. $start = 0;
  38.  
  39. // browse.php can also paginate results with an optional
  40. // GET parameter with the filename of the image to start from:
  41.  
  42. if(isset($_GET['start']) && strlen($_GET['start'])>1){
  43.     $start = array_search($_GET['start'],$names);
  44.  
  45.     if($start === false){
  46.         // Such a picture was not found
  47.         $start = 0;
  48.     }
  49. }
  50.  
  51. // nextStart is returned alongside the filenames,
  52. // so the script can pass it as a $_GET['start']
  53. // parameter to this script if "Load More" is clicked
  54.  
  55. $nextStart = '';
  56.  
  57. if($names[$start+$perPage]){
  58.     $nextStart = $names[$start+$perPage];
  59. }
  60.  
  61. $names = array_slice($names,$start,$perPage);
  62.  
  63. // Formatting and returning the JSON object:
  64.  
  65.     'files' => $names,
  66.     'nextStart' => $nextStart
  67. ));

No entiendo muy bien lo que hace, escanea el directorio y luego mediante un array va clasificando los datos y emplea la función filemtime.

Como no se programar lo veo complicado, pero si logro hacer que se muestre la última imagen subida al server, os pegaré el script aquí por si a alguien le viene bien.

Un saludo a todos !!