Welcome Guest, Not a member yet? Register   Sign In
displaying images from a folder
#4

[eluser]Yorick Peterse[/eluser]
I had a function written for a gallery which would display all images in folder x, the function itself is pretty clumsy and could have been done way better, but it might be helpful.

Code:
function Category() {
        $URL_Title     = $_GET['title'];        
        
        if($URL_Title !== null) {
            //Check if the category folders that belong to the current title exist and fetch their contents
            $Full_Dir         = "gallery/normal/$URL_Title/";
            $Thumb_Dir        = "gallery/thumbs/$URL_Title/";
            //Scan directories
            if(file_exists($Full_Dir)) {
                $Scan_Full        = scandir($Full_Dir);
            }
            if(file_exists($Thumb_Dir)) {
                $Scan_Thumb        = scandir($Thumb_Dir);
            }
            echo "<div id=\"image-wrap\">";
            for($i = 0; $i<count($Scan_Thumb); $i++) {
                if($Scan_Thumb[$i] != "." && $Scan_Thumb[$i] != ".." && preg_match('/[.](jpg)|(gif)|(png)$/',$Scan_Thumb[$i])) {
                    $FullName = str_replace("thumb_","",$Scan_Thumb[$i]);
                    $ThumbLayout = <<<THUMBS
                    <div class="image-box">
                        <a href="$Full_Dir$FullName" title="$FullName" rel="lightbox[roadtrip]"><img src="$Thumb_Dir$Scan_Thumb[$i]" alt="$Scan_Thumb[$i]" /></a>
                    </div>
THUMBS;
                    echo $ThumbLayout;
                }                
            }
            echo "</div>";
        }
        else {
            echo "<h2>The page you requested does not exist!</h2>";
        }
        echo "</div>";
    }

In this case the "scandir()" function is the most important function:

http://nl2.php.net/scandir


Messages In This Thread
displaying images from a folder - by El Forum - 05-02-2009, 03:26 AM
displaying images from a folder - by El Forum - 05-02-2009, 03:57 AM
displaying images from a folder - by El Forum - 05-02-2009, 04:02 AM
displaying images from a folder - by El Forum - 05-02-2009, 06:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB