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

  • SEARCH
  • Home
  • 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 877085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:32:51+00:00 2026-05-15T11:32:51+00:00

This function grabs all the jpegs from folders which match the page name and

  • 0

This function grabs all the jpegs from folders which match the page name and prints a background image. On the homepage it searches all the sub directories and chooses one at random. What i would like is to exclude (on the homepage only) certain files which match an array of names…can anyone help?

$isHome = $this->level() == 0;

$path = 'public/images/bg/';
if (!$isHome) $path .= $this->slug;

$homepagefile = URL_PUBLIC.'public/images/bg/'.$this->slug.'/main.jpg';

$bgimagearray = array();
$iterator = new DirectoryIterator($path);
foreach ($iterator as $fileinfo) {
    if ($fileinfo->isFile() && !preg_match('\.jpg$/', $fileinfo->getFilename()) &&  !$isHome) {
        $bgimagearray[] = "'" . $fileinfo->getFilename() . "'";
    } else if ($fileinfo->isDir() && $isHome) {
        $iterator2 = new DirectoryIterator($path . $fileinfo->getFilename());
        foreach ($iterator2 as $fileinfo2) {
            if ($fileinfo2->isFile() && !preg_match('\.jpg$/', $fileinfo2->getFilename())) {
                $bgimagearray[] = "'" . $fileinfo->getFilename() . '/' . $fileinfo2->getFilename() . "'";
            }
        }
    }
}

$bgimage = array_rand($bgimagearray);
  • 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-05-15T11:32:51+00:00Added an answer on May 15, 2026 at 11:32 am

    In simple terms, you just need another condition in the if statement when filtering which items go into the bgimagearray for the homepage.

    if ($fileinfo2->isFile() 
        && !preg_match('\.jpg$/', $fileinfo2->getFilename())
        && ! in_array($fileinfo2->getFilename, $my_blacklist_array) // added
    ) {
    

    Aside: your code is a little messy and your task could likely be solved with prettier code structure; however, that would be a rewrite of your existing code rather than answering the question posed.

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

Sidebar

Related Questions

I'm try to run this function, which grabs all the checked checkbox values in
i'd like to write a function which grabs all fields from a database table
I've got a function that currently grabs all folders and sub-folders to check the
$('h2').each(function() { $('UL.chapters_list').append($('<li/>', {text: $(this).text()})) }); This code grabs all of the <H2> tags
I've created a view which grabs all the datas from multiple tables and I
I have a query which grabs all users from the wait table based on
So, I have this code that grabs a bunch of data from the database,
I have a click function that grabs the #id of a DIV all the
I am using this PHP function to grab all <img> tags within any given
I'm working on a web crawler that grabs data from sites all over the

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.