Get files from a directory in random order using php (xampp)

i'm building a wordpress theme and i'm trying to get the all the jpg files from a directory in random order using php.... im using Xampp on win7 (localhost).

this is the code:

<? 
    $dir =  get_template_directory_uri().'/images/top/';

    $file_display = array ('jpg', 'jpeg');
    if(file_exists($dir) == false){
        echo 'Directory \'', $dir, '\' not found';
    } else {
       $dir_contents = scandir($dir);
       shuffle($dir_contents);
       foreach ($dir_contents as $file) {
           $file_type = strtolower(end(explode('.', $file)));
           if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true){ 
                echo '<img  src="', $dir, '/', $file, '" alt="', $file, '" />';    
           }
       }
   } 
?>

i always get

Directory 'http://localhost/ni/wp-content/themes/A/images/top/' not found 

i also tried to change

$dir =  get_template_directory_uri().'/images/top/';

to:

    $dir = "C:\xampp\htdocs\Ni\wp-content\themes\A\images\top\";

but still no luck, any help would be appreciated!

Answers


This is how i made it work.

  <? 
            $dir =  get_template_directory().'/images/top';
            $imageDir= get_template_directory_uri().'/images/top';
            $file_display = array ('jpg', 'jpeg');
            if (file_exists($dir) == false) {
              echo 'Directory \'', $dir, '\' not found';
            } else {
              $dir_contents = scandir($dir);
              shuffle($dir_contents);
              foreach ($dir_contents as $file) {
                $file_type = strtolower(end(explode('.', $file)));
                if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) {
                  echo '<img src="', $imageDir, '/', $file, '"  />';
                }
              }
            } 
  ?>

Need Your Help

Order of UIViewController initialization and loading

iphone objective-c cocoa-touch uiviewcontroller

I'm fairly new to UI programming on the Mac and iPhone, and I've run across something that somewhat puzzles me.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.