Picture Gallary funktion

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Enjoiskater
Forum Newbie
Posts: 3
Joined: Sun May 11, 2008 11:45 am

Picture Gallary funktion

Post by Enjoiskater »

Hello

I´m pretty new when it comes to PHP and I´m trying to learn and right know I´m trying to build a new picture gallery to my site. I have gotten this code from a friend to help me get started but I´m stuck right know.

Code: Select all

<?php
/**
* Returns an array with the paths of all images in the directory $dir.
* If $fullDir is set to true, subdirectives and their images will be
* returned as well, as arrays withing the array.
*
* @param $dir The directive in which to look for images
* @param $fullDir Decide weather or not to look in subdirectives as well
*
* @return An array holding image paths and possibly subarrays holding
           paths of images in subdirectives
*
*/
function getImagesInDir($dir = 'Bilder/Bildserier/Naruto Ultimate Ninja Storm', $fullDir = true)
{      
    $allowedExtensions = array('jpg', 'gif', 'png');
    $allImages = array();
    
    // Om $dir är ett giltligt direktiv
    if(is_dir($dir)) {
        if($dh = opendir($dir)) {
            // Medan det finns fler filer, fortsätt att läsa in dem
            while(($file = readdir($dh)) !== false) {
                // Ignorera s.k. 'punkt-filer'
                if($file != "." && $file != "..") {
                    // Om denna fil är en katalog (mapp)
                    if(filetype($file) == 'dir') {
                        $tmp = getImagesInDir($dir.$file, $fullDir);
                        if (!empty($tmp)) {
                            $allImages[] = $tmp;
                        }
                    } elseif(in_array(getExtension($file), $allowedExtensions)) {
                        $allImages[] = $dir.$file;
                    } // if
                } // if
            } // while
        } // if
    } // if
    return $allImages;
}
 
/**
* Returns the file extension of a file
*
* @param $imageName The complete image name
*
* @return The file's extension, excluding a dot
*/
function getExtension($imageName)
{
    return end(explode('.', $imageName));
}
?>
 
 
Thats the code but I cant get PHP to write out the pictures. I have tried some diffrent ways but it dosen´t work at all and I´m hoping that maybe someone can help me to get the code to show me the pictures.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Picture Gallary funktion

Post by JAB Creations »

I'm looking at the output which is totally blank so I was wondering why and then presumed that you're loading images from a different source.

Then I still see no HTML output...or anything...

So I looked through your code and there is nothing being echoed.

So I attempted to echo nearly all of your variables.

...so would it be safe to presume this is not all of the PHP you're working with?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Picture Gallary funktion

Post by JAB Creations »

Haha I just realized the function wasn't being called. I've been working with functions for so long in JavaScript, working with PHP for a few years now, and I have just recently started using functions in PHP. :|

Ok so I executed the function at the end of the page and there are some errors...

Code: Select all

getImagesInDir();
Functions are like taxis, they won't show up unless you call for them.
Enjoiskater
Forum Newbie
Posts: 3
Joined: Sun May 11, 2008 11:45 am

Re: Picture Gallary funktion

Post by Enjoiskater »

Hello, thanks for the answer. But that is what I´m having problems with. I cant call the function, I dont know how write to call it because I have tried some diffrent ways but with no luck. So what I really would like help with is to actully call the function and make the code work.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Picture Gallary funktion

Post by JAB Creations »

Did you read my last post?
Enjoiskater
Forum Newbie
Posts: 3
Joined: Sun May 11, 2008 11:45 am

Re: Picture Gallary funktion

Post by Enjoiskater »

JAB Creations wrote:Did you read my last post?
Sorry, I must have jumped over the post. Thanks I gonna try it and see what there are for som errors.
Post Reply