Picture Gallary funktion
Posted: Sun May 11, 2008 11:49 am
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.
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.
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));
}
?>