Currently I have a script running to grab all the images in a directory based on ending with “154×154.jpg”. Basically what I’m doing is going through a gallery directory and looking for all the thumbnails of images, which I will then output in a sliding gallery on the main page of a website.
<?php
// loop through the images
$count = 0;
$images = array();
foreach (glob("../../uploads/2012/05/*154x154.jpg") as $filename) {
$images[$count] = $filename;
$count++;
}
for ($i = 0; $i < 7; $i++) {
$random = mt_rand(1, $count - 1);
echo '<li><a class="gal_img" href="#">';
echo '<span class="roll"></span>';
echo '<img class="image" src="'.$images[$random].'" height="154" width="154" alt="" />';
echo '</a></li>';
}
?>
This works perfectly fine as it is, but what I need to do is be able to grab the files from within a directory above the current one. To be more specific:
image folder: http://root/wp-content/uploads/2012/05/
theme folder: http://root/wp-content/themes/theme_folder/
** EDIT **
Everything works now with the above code it executes fine, when I go directly to the file. However using it within the theme generates everything except for the filepaths in the code. Using wordpress 3.3.2
Try:
Update:
Of course, this is a relative path and only works if the file you need to include is one level up from your script’s current working directory. Solution: use an absolute path, ie. one that begins with
/. Also, keep in mind that the absolute path is a path on the disk, not the root folder of your website.