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;
This seems like the perfect opportunity to use PHPs
glob()function.