Quelltext der Datei: http://www.michaelster.ch/jsTestFolder/getimages.php

Dateigrösse: 900 bytes

[Anzeige ohne Zeilennummern]


1 
<?php
//PHP SCRIPT: getimages.php
Header("content-type: application/x-javascript");

// This function gets the file names of all images in the current directory
// and ouputs them as a JavaScript array
function returnPics($dirname = ".",$limiter)
{
    $pattern   = "/.png$|.gif$|.jpg$|.jpeg$/";
    //$pattern   = "\(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)";
    $files        = array();
    $curimage  = 0;
    if($handle = opendir($dirname))
    {
        while(false !== ($file = readdir($handle)) && $curimage <= $limiter)
        {
            if(preg_match( $pattern, $file ))
            {
                echo ' eMulePics['.$curimage.'] = "'.$file .'"; ### ';
                $curimage++;
            }
        }
        closedir($handle);
    }
}

echo 'var eMulePics=new Array(); ';     // Define array in JavaScript
echo ' var picsPath="../img/"; ';        // Define variable in JavaScript
returnPics('../img/', 10);             // Output array with the file names of images
?>