/ Published in: PHP
Returns all the images in a folder randomly.Listed back in this format: { src: "/'.$localdir.$file.'" },
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getImages($folder){ $basedir = "/home/cochipp/public_html/"; // base directory for the server $localdir = "images/banners/".$folder."/"; // local directory and the folder passed $dirname = $basedir.$localdir; $images = ""; $i = 0; if(($file != ".") and ($file != "..") and ($file != "index.html")){ $images_arr[$i] = '{ src: "/'.$localdir.$file.'" },'; $i++; } } foreach($images_arr as $image){ $images .= $image; } // strip off last comma echo $images; }