Jump to content


Photo

A little help with this function please


  • Please log in to reply
5 replies to this topic

#1 bbunlock

bbunlock
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationEngland

Posted 09 June 2006 - 02:29 PM

Hi peeps thanks for taking the time to read this.

ok I have a small gallery script that reads the contents of a given folder eg albums/album1 and displays thumbnails of the images in the folder, now all that works great but I also have another script that uses the album1 folder, now if this script acccesses the album1 folder it will create a thumbnail folder called .thumbs and another folder called .resized.

so for example the gallery script will look into album1 and it automaticaly creates its own thumbnails and shows the images in that folder, however the other script that accesses the album1 folder creates .thumbs and .resized folders in there, now what I want is for the gallery script NOT to look into these 2 .folders? below is what I believe to be the parts of the gallery script that looks and reads the folders so if somone can tell me what to add to them to not have the gallery script look at .thumbs and .resized that would be great.

the function would be called witht he following code
$contents = dir_get_contents ( $conf_root . 'albums/', $album );

and the function(s) that relate tot his are I believe

function dir_get_contents ( $root, $dir )
{
    $dir = $dir != '' && $dir != '/' ? trim ( $dir, '/' ) : '';
    $path = $root . $dir . '/';
    $h = opendir ( $path );
    if ( !$h )
    {
        exit ( 'Unable to open ' . $path );
    }

    $contents['images'] = array( );

    $contents['albums'] = array ( );

    while ( false != ( $f = readdir ( $h ) ) )
    {
        if ( $f != '.' && $f != '..' )
        {
            if ( is_dir ( $path . $f ) )
            {
                $info = dir_info ( $path . $f );

                $contents['albums'][] = array ( 'name' => $f, 'albums' => $info['dirs'], 'images' => $info['files'] );
            }
            elseif ( preg_match ( '#.jpg$#i', $f ) )
            {
                $info = getimagesize ( $path . $f );
                $dimension = $info[0] . 'x' . $info[1];
                $contents['images'][] = array ( 'name' => $f, 'dimension' => $dimension, 'modified' => filemtime ( $path . $f ), 'size' => filesize ( $path . $f ) );
            }
        }
    }
    return $contents;
}


function dir_info ( $dir )
{
    $dir = $dir != '' && $dir != '/' ? trim ( $dir, '/' ) . '/' : '';
    $h = @opendir ( $dir );
    if ( !$h )
    {
        exit ( 'Unable to open ' . $dir );
    }
    $count['dirs'] = 0;
    $count['files'] = 0;
    $count['size'] = 0;
    while ( false != ( $f = readdir ( $h ) ) )
    {
        if ( $f != '.' && $f != '..' )
        {
            if ( is_dir ( $dir . $f ) )
            {
                $count['dirs']++;
            }
            else
            {
                $count['files']++;
                $count['size'] += filesize ( $dir . $f );
            }
        }
    }
    return $count;
}

so if you could please help me to make it so that the functions above ignor .thumbs and .resized that would be just great, I am not a php programmer so im a little lost on this one, I have managed to to some things in php but no matter what I try it just isnt working for me.

ps you can see an example of what I mean by going to this link [a href=\"http://www.sitebuz.com/memsites/tester/gallery/index.php?album=test&sortby=name&order=asc\" target=\"_blank\"]http://www.sitebuz.com/memsites/tester/gal...=name&order=asc[/a]

thank you

#2 joquius

joquius
  • Members
  • PipPipPip
  • Advanced Member
  • 319 posts

Posted 09 June 2006 - 02:55 PM

just change the input $dir to something other than album1. it must be set to this somewhere else in the script. The question is don't you want both scripts to work?
z..z..z..z..z..z..z..z..

#3 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 03:06 PM

in your while loop:
while ( false != ( $f = readdir ( $h ) ) )
    {
if($f == '.thumbs' || $f == '.resized')
{
continue;
}

[table]



Don't worry, the printer fairies will sort it out.

#4 bbunlock

bbunlock
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationEngland

Posted 09 June 2006 - 03:10 PM

yes I realy need both scripts to work, now as it is at the moment both scripts start at the albums folder and read what is in that folder, now there will be no images in the album folder only other folder (each folder represents an album) so for example the album folder may have albums/album1 albums/album2 albums/album3 albums/album4 etc

now when the gallery script is run it sees these album folders and creates links to them, below is a link to show what I mean

[a href=\"http://www.sitebuz.com/memsites/tester/gallery/index.php\" target=\"_blank\"]http://www.sitebuz.com/memsites/tester/gallery/index.php[/a]

now when you click on an album from the link above (only album1 has images in it at the moment) the gallery script creates thumbnails for the images in there and shows them as it should do.

now the other script also has access to the albums folder and shows links to the albums in it (album1, album2 etc), now when this script access a album folder it creates at least 1 folder called .thumbs and if the images are resized using this script it also creates a folder called .resized.

now the problem is that the gallery script will look into album1 and show the thumbnails but it also see's .thumbs and .resized as sub albums and shows a link to them, these are not new albums but woking folders for the second script, see link below for example

[a href=\"http://www.sitebuz.com/memsites/tester/gallery/index.php?album=album1&sortby=name&order=asc\" target=\"_blank\"]http://www.sitebuz.com/memsites/tester/gal...=name&order=asc[/a]

now as you can see from the second link it shows the .thumbs folder at the top as a sub album, I want the gallery script to not create a link for any folder it see's starting with .thumbs or .resized.

thanks in advance

#5 Fyorl

Fyorl
  • Members
  • PipPipPip
  • Advanced Member
  • 273 posts
  • LocationUK

Posted 09 June 2006 - 03:14 PM

Just do what I suggested and make sure when you're looping through the contents of the folders with your second script stick:
if($f == '.thumbs' || $f == '.resized'){ continue; }
at the top of the loop
[table]



Don't worry, the printer fairies will sort it out.

#6 bbunlock

bbunlock
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationEngland

Posted 09 June 2006 - 03:14 PM

@ Fyorl

thats exactly what I was looking for, added that little extra code to both of the functions above and it now doesnt look into those fodlers.

thanks you all very much for the help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users