Dateigrösse: 900 bytes
1 <?php 2 //PHP SCRIPT: getimages.php 3 Header("content-type: application/x-javascript"); 4 5 // This function gets the file names of all images in the current directory 6 // and ouputs them as a JavaScript array 7 function returnPics($dirname = ".",$limiter) 8 { 9 $pattern = "/.png$|.gif$|.jpg$|.jpeg$/"; 10 //$pattern = "\(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$)"; 11 $files = array(); 12 $curimage = 0; 13 if($handle = opendir($dirname)) 14 { 15 while(false !== ($file = readdir($handle)) && $curimage <= $limiter) 16 { 17 if(preg_match( $pattern, $file )) 18 { 19 echo ' eMulePics['.$curimage.'] = "'.$file .'"; ### '; 20 $curimage++; 21 } 22 } 23 closedir($handle); 24 } 25 } 26 27 echo 'var eMulePics=new Array(); '; // Define array in JavaScript 28 echo ' var picsPath="../img/"; '; // Define variable in JavaScript 29 returnPics('../img/', 10); // Output array with the file names of images 30 ?> 31