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 6771371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:25:26+00:00 2026-05-26T15:25:26+00:00

I try to write a function which returns an array of images for a

  • 0

I try to write a function which returns an array of images for a jQuery image slider.

And now I’m getting a bit stuck in getting the right logical code. And I’m thinking mabey the whole structure is wrong?
I can get the right path for 1 file, but an array of the related files doesn’t seem to work.

##info past to the function:
$id = '11101';
$dir = "myimgdir/";
$thumbs = 'TN';
$medium = 'M';

##the files in the dir are named like this:
11101x1xTN //thumbnail
11101x2xTN
11101x3xTN
11101x1xM //some img but in medium size
11101x2xM
11101x3xM

So:

$dir = "$dir$id/";      
$get_opts = array($thumbs, $medium);

// array to hold return value 
$retval = array();

   //full dir
   $fulldir = "{$_SERVER['DOCUMENT_ROOT']}/$dir"; 

$d = @dir($fulldir) or die("getImages: Failed opening directory $dir for reading"); 
while(false !== ($entry = $d->read())) {

  $fullpath = escapeshellarg("$fulldir$entry");
  $file_extension = end(explode('.', $fullpath));
  $file_name = basename($entry, $file_extension);   


 ####here I get stuck
    foreach ($get_opts as $get_opt) {           
        if (strpos($file_name, $get_opt)) { //so 11101x1xTN gontains TN
            $retval[] = array( 
                'TN'      => "/$dir$entry", 
                'TNsize'  => getimagesize("$fulldir$entry"),

                ####how to return the medium path as well (11101x1xM)
                'M'  => "/$dir", 
            );
        }           
    }



}

$d->close();    
return $retval;
  • 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-26T15:25:26+00:00Added an answer on May 26, 2026 at 3:25 pm

    This seems like the perfect opportunity to use PHPs glob() function.

    <?php
    $thumbs = glob('*TN*');
    foreach ($thumbs as $filename) {
        $image_path = '/' . $dir . $filename;
        $medium_image_path = str_replace('TN', 'M', $image_path);
        if(!is_file($medium_image_path)) {
            $medium_image_path = '';
        }
        $retval[] = array( 
                'TN'      => $image_path,
                'TNsize'  => getimagesize($image_path),
                'M'  => $medium_image_path, 
            );
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a function which removes elements from an array of integers
I am trying to write a function which returns a string created from two
I try to write a function which takes any other function and wraps a
I need to write a delegate function that can 'wrap' some while/try/catch code around
I would like to write a function which takes an fstream , processes it,
I'm trying to write a Java function that takes a Class<?> and returns a
I wrote my bind function which returns a nullary functor because I don't have
I try to write KSH script for processing a file consisting of name-value pairs,
I try to write to a large file, but it seems like it does
I try to write a simple client/server application (all application is a bluetooth service

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.