Jump to content

Problem with a gallery-script


klofisch

Recommended Posts

Hello,

I tried to use the following script. I think i got it from php-resource.net

The problem is, i want to open the images in a popup by Javascript.
I change this Line

[code]  <a href='$current_dir$pic' ><img src='image_resize.php?i=$d$pic&w=$w&h=$h' alt='$pic' />[/code]

to this

[code]<a href='$current_dir$pic' onClick="return popup(this,790,651)"><img src='image_resize.php?i=$d$pic&w=$w&h=$h' alt='$pic' />[/code]

but without any success:

What i need to do?


FULL CODE

[code]
<?

echo '<h1>Photo Gallery: '.$title.'</h1>';



//-------------------------------- Directory Navigation -----------------------------
function dir_list($dir)
{
  global $title;
  $dlist = array();

  if ($hdir = opendir('./'.$dir))
  {
    while ($obj = readdir($hdir))
      {
        if (((preg_match("/^./",$obj)==0) && (!eregi('^(.*).[code=php:0]$', $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'><ul>\n<li>Folders:</li>\n";

  echo "<li> <a href='?'>$title &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 "<li> <a href='?d=$dirparent$dirsub'>$dirsub &raquo; </a></li>\n";
        $dirparent .= $dirsub.'/';
    }

  foreach ($dlist as $link)
  {
    echo "<li><a href='?d=$dir$link'>[$link]</a></li>\n";
  }
  echo "</ul>\n</div>\n";
}



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



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



if($_GET['d'])
{
  $d = $_GET['d'].'/';
  $dd = 'd='.$_GET['d'].'&'; // for use in passing to URL strings
  $current_dir .= $d;
}

opendir($current_dir);

if ($show_folders)
  dir_list($current_dir);



//--------------------------------------- Create list of Images ------------------------
$list = array();

if ($dir = opendir('./'.$current_dir))
{
  while ($file = readdir($dir))
  {
      //if((is_file($file)) && ((!eregi('^(.*).[code=php:0]$', $file)) && (!eregi('^(.htaccess)$', $file))))

      // find all JPG, PNG or GIF images
      if (eregi('^(.+.(((j|J)(p|P)(g|G))|((g|G)(i|I)(f|F))|((p|P)(n|N)(g|G))))$', $file))
        $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



//-------------------------------------- Create Thumbnails and Gallery ------------------
foreach ($list as $pic)
{
      $fp = $current_dir.$pic;
      if($i < $thumb+$limit)
      {
      //echo "<p class='thumb'><tt><a href='$current_dir$pic'><img src='tn/$pic' alt='$pic' /><br />$pic</a> - [".getfilesize(filesize($fp))."]</tt></p>\n";
      $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));

      if ($hide_extension)
        $extensions = array(".jpg", ".JPG", ".gif", ".GIF", ".png", ".PNG");
      if ($show_name)
      $name = str_replace($extensions, '', $pic);
      echo "<p class='thumb'>
                  <tt>
                      <a href='$current_dir$pic' ><img src='image_resize.php?i=$d$pic&w=$w&h=$h' alt='$pic' /><br />
                      $name<br /></a>\n";
        if($idim)
          echo "            [$i_width x $i_height]";
        if($idim && $isize)
            echo " - ";
        if ($isize)
            echo "            [$i_size]";
      echo "        <br />
                  </tt>
              </p>\n";
      $i++;
    }
}




//---------------------------------------Page Navigation -----------------------------
$page = 0;
if(!$pg)
  $pg = 1;
echo "<div id='nav'>\n<ul>\n";

if($thumb > 0)
  echo "<li><a class='prev' href='?".$dd."pg=".($pg-1)."'>&laquo; Prev $limit</a></li>\n";
else
  echo "<li><div class='prev'>&laquo; Prev $limit</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)."'>Next $limit &raquo;</a></li>\n";
else
  echo "<li><div class='next'>Next $limit &raquo;</div></li>\n";

?>

[/code]
Link to comment
Share on other sites

  • 7 months later...
Wouldn't you need something like the below in your header?
[code]
<SCRIPT TYPE="text/javascript">
<!--
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
  href=mylink;
else
  href=mylink.href;
window.open(href, windowname, 'width=400,height=200,scrollbars=yes');
return false;
}
//-->
</SCRIPT>

[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.