Jump to content

A little help with this function please


bbunlock

Recommended Posts

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 [b]NOT[/b] 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
[code]$contents = dir_get_contents ( $conf_root . 'albums/', $album );[/code]

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

[code]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;
}[/code]

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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