Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7889773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:11:03+00:00 2026-06-03T06:11:03+00:00

Currently I have a script running to grab all the images in a directory

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:11:04+00:00Added an answer on June 3, 2026 at 6:11 am

    Try:

    foreach (glob("../images/*154x154.jpg") as $filename) {
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a ToDo-Script for a project i have running. Now there is
We currently have an error catching script for all our PHP sites. This script
I have an SQL script (currently running against SQLite, but it should probably work
I currently have a script running and didn't think it would take so long
I currently have a shell script that process many images one after the other,
I have an IronPython script that looks for current running processes using WMI. The
I currently have a script that scrapes proxies off websites, but I'm just wondering
I currently have a script which allows me to output the list of files
Currently we have a script that does maven build + tomcat deploy. Deploying to
I currently have a python script that runs every few minutes and picks up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.