Ver Mensaje Individual
  #1 (permalink)  
Antiguo 25/08/2008, 07:15
titotito
 
Fecha de Ingreso: agosto-2008
Mensajes: 15
Antigüedad: 15 años, 9 meses
Puntos: 0
Como cambio el directorio en este script?

Se trata de una galeria que no necesita bases de datos, simplemente subes una carpeta con fotos dentro del directorio donde esta el script y crea un album.

El problema es que como tengo el script y las demas carpetas dentro de un directorio llamado "galeria", y llamo al script con un include desde el index que esta en el directorio superior me muestra las carpetas del directorio del index como si fueran los albumes, y no muestra los de la carpeta galeria.

He probado escribiendo detras de algunas variables /galeria/ y cosas asi pero nada

Código:
<?php
$limit = 9;           // Numero de Imagenes por Pagina
$w = 116;              // Ancho Max thumbnails
$h = 100;               // Alto Max thumbnails
$show_folders = 1;     // Set to 1 to show folder list, 0 to turn off
$ititle = 0;           // Set to 1 to display image name (title)
$idate = 0; 		   // Set to 1 to display file date (modified)
$isize = 1;            // Set to 1 to display image filesize
$idim =1;             // Set to 1 to display image dimensions

//============================================

if($pg = $_GET['pg'])
{
  $thumb = (($pg-1)*$limit);
  $i = $thumb;
}
else
  $i = 0;


$dirlist = dirname($_SERVER['SCRIPT_NAME']);


$subdir = explode("/", $dirlist);


$subdir = array_reverse($subdir);

$replace = array ("_", "/");
$with = array (" ", " - ");
$title = str_replace($replace, $with, $_GET[d]);

if(ereg("\.\.", $_GET['d']))
  header ("Location: ?");

if($_GET['t'])
  $limit = $t;

//additional paramaters for <p> based on whether name or dimensions is displayed
$pwidth = $w+12;
$pheight = $h+12;
if($ititle)
  $pheight +=10; // increase height of thumbnail <p> element
if($isize || $idim) // if displaying dimensions or size of image, increase height of thumbnail <p> element.
  $pheight +=10;


?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
	"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style type="text/css">

body {background-color: #ffffff; text-align: center; margin: 0; padding:0px;
	font-family: verdana; font-size: 12px; color: #000000;}

#container {width: 420px; margin: 0; text-align: center; }



#thumbnails { }
p.thumb {width: <? echo $pwidth; ?>px; height: <? echo $pheight; ?>px;
		margin: 1px; padding: 2px; float: left;
		font-size: 10px; text-align: center;
		background-color: #f6d272; border: 1px solid #ccc;
		border-style: solid; border-width: 1px; border-color: #ccc #a0a0a0 #a0a0a0 #ccc;
/*border-width: 1px 2px 2px 1px; border-style: solid;
border-color: #aaa #000 #000 #aaa;*/}
p.thumb a {color: #000; font-weight: bold;  }
tt {font-family: verdana; font-size: 10px; color: #000; }



.pagenav {position: relative; margin: auto; clear: both; float: left;
		height: 20px; width: 100%;	text-align: left; }
	.pagenav ul, .pagenav li {margin: auto; padding: 0; list-style-type: none; }
	.pagenav li {float: left; text-align: left;  }
	.pagenav li.current a.page {font-weight: bold; color: #fff; background-color: #aaa; }
	.pagenav a.page {display: block; padding: 2px 5px 2px 5px; color: #000000; }
	.pagenav a.prev, .pagenav a.next, .pagenav .prev, .pagenav .next {display: block; width: 65px; padding: 2px 5px 2px 5px; }
	.pagenav a:hover {color: #c07911;  }

a {color: #000000; text-decoration: none; }
a:hover, a:active {color: #c07911; text-decoration: underline;}

p.footer {position: relative; float: left; clear: both; margin: -20px auto auto auto; }

</style>
<link href="css_thumbnail.css" rel="stylesheet"  type="text/css" />
<script type="text/javascript" src="js-thumbnail.js"></script>
</head>

<body>
<div id="container" align="center" style="text-align:center; text-align:center">
<?



// =============================== GALLERY FUNCTIONS ================================


//-------------------------------- Directory Navigation -----------------------------

function dir_list($dir) // gets the list of directories in the current folder
{
  global $subdir;
  $rootname = str_replace("_", " ", $subdir['0']); // name of the root photo gallery
  $dlist = array();

  if ($hdir = opendir('./'.$dir))
  {
    while ($obj = readdir($hdir))
      {
        if (((preg_match("/^\./",$obj)==0) && (!eregi('^(.*).[php]$', $obj))) && is_dir($dir.$obj))
        //if(is_dir($dir.$obj))
          $dlist[] = $obj;
      }
    closedir($hdir);
  }
  else
    die('Cannot list files for ' . $dir);

  asort($dlist);
  echo "<div id='dirnav' style='text-align:left'><ul>\n";

  //echo "<li> <a href='?'>$rootname &raquo; </a></li>\n";
    $dirtree = explode("/", $_GET['d']); // parse directory tree from passed "d"
  if(!$_GET['d'])
    array_shift($dirtree); // remove redundant "." directory from tree
    foreach ($dirtree as $dirsub)
    {
	    echo "<img src='volver.png' border='0' align='absmiddle'> <a href='index.php'>Volver a indice de galerias</a>\n";
	    $dirparent .= $dirsub.'/';
    }

  foreach ($dlist as $link)
  {
    echo "<img src='album.png' align='absmiddle'> &nbsp;<a href='?d=$dir$link'>$link (ver galeria)</a><br>\n";
  }
  echo "</ul>\n</div>\n";
}



//---------------------------------------Page Navigation -----------------------------

function pagenav() // Writes the numbe rof thumbs, remaining pages, next and prev links
{
  global $page, $pg, $thumb, $dd, $limit, $numtotal, $numremain;

  $page = 0;
  if(!$pg)
    $pg = 1;
  echo "<div class='pagenav'>\n<ul>\n";

  if($thumb > 0)
    echo "<li><a class='prev' href='?".$dd."pg=".($pg-1)."'>&laquo; Anterior</a></li>\n";
  else
    echo "<li><div class='prev'>&laquo; Anterior</div></li>";

  while($page*$limit < $numtotal)
  {
    $page ++;
    unset($cur);
    if($page == $pg)
    {
      $cur = ' class="current"';
    }
    echo "<li$cur><a class='page' href='?".$dd."pg=$page'>".($page)."</a></li>\n";
  }

  if($numremain > $limit)
    echo "<li><a class='next' href='?".$dd."pg=".($pg+1)."'>Siguiente&raquo;</a></li>\n";
  else
    echo "<li><div class='next'>Siguiente&raquo;</div></li>\n";
  echo "</ul>\n</div><br><br><br>";
}




//------------------------------------- Get image file size ----------------------------------

function getfilesize($size) // gets file size for each image
{
  $units = array(' B', ' KB', ' MB', ' GB', ' TB');
  for ($i = 0; $size > 1024; $i++) { $size /= 1024; }
  return round($size, 2).$units[$i];
}

//====================================== END FUNCTIONS =========================================



//------------ Set which folder we are viewing

if($_GET['d']) // d variable is in URL string, used for navigating subdirectories
{
  $d = $_GET['d'].'/';
  $dd = 'd='.$_GET['d'].'&'; // for use in passing to URL strings
  $current_dir .= $d;
}

 opendir($current_dir); // open the dir to browse for images

if ($show_folders)
  dir_list($current_dir); // write out the directory navigation (folder list)





//----------- Create list of Images

$list = array();

if ($dir = opendir('./'.$current_dir))
{
  while ($file = readdir($dir))
  {
      //if((is_file($file)) && ((!eregi('^(.*).[php]$', $file)) && (!eregi('^(\.htaccess)$', $file))))
      //if((eregi('^(.*).[jpg]$', $file)) && (!eregi('^(.*).[php]$', $file)))
      //if (eregi('^(([:alnum:])*)\.((j|J)(p|P)(g|G)))$', $file))

    if (eregi('.jpg', $file)) //If file is a JPG
      $list[] = $file;
  }
    closedir($dir);
}

asort($list); // sort alpha
$numtotal = count($list); //total number of thumbs

if ($thumb)
{
  $s = 0;
  while($s < $thumb)
  {
    array_shift($list);
    $s++;
  }
}

$numremain = count($list); // total remaining thumbs in the array (folder)

if ($_GET['d'])
{
pagenav(); //page links at top of gallery
}



//--------- Create Thumbnails and Gallery

echo "<div id='thumbnails'>";
foreach ($list as $pic)
{
   	$fp = $current_dir.$pic;
   	if($i < $thumb+$limit)
   	{
	  $image = $currentdir.$pic;
	  $i_size = getfilesize(filesize($fp));
	  $i_area = getimagesize($fp);
	  $i_width = $i_area[0];
	  $i_height = $i_area[1];
	  //$i_mtime = date("d F Y ", filemtime($fp));
	  $name = str_replace('.jpg', '', $pic);
	  echo "<p class='thumb'><tt>\n";
	  echo "<a href='$current_dir$pic' rel='thumbnail'>";
	  echo "<img src='image_resize.php?i=$d$pic&w=$w&h=$h' alt='$pic' border='0' />";
	  if($ititle)
	    echo "<br /><span class=\"iname\">$name</span>";
	  if ($idate)
	    echo  "  ".date("F d", filemtime($current_dir.$pic));
	  echo "  </a>\n<br />";
	  if($idim)
	  	echo "<span class=\"idim\">$i_width x $i_height</span><br/>";
	  if($idim && $isize)
	    echo "  ";
	  if ($isize)
	    echo "<span class=\"isize\">[$i_size]</span>";
	  echo "</tt></p>\n\n";
	  $i++;
	}
}
echo "</div>";



?>
</div>

</body>
</html>