PHP read dir和return数组,带有相关图像链接的路径

PHP read dir和return数组,带有相关图像链接的路径,php,arrays,image,Php,Arrays,Image,我尝试编写一个函数,为jQuery图像滑块返回图像数组 现在我在获取正确的逻辑代码方面遇到了一些困难。我想mabey整个结构都错了? 我可以为1个文件找到正确的路径,但相关文件的数组似乎不起作用 ##info past to the function: $id = '11101'; $dir = "myimgdir/"; $thumbs = 'TN'; $medium = 'M'; ##the files in the dir are named like this: 11101x1xTN /

我尝试编写一个函数,为jQuery图像滑块返回图像数组

现在我在获取正确的逻辑代码方面遇到了一些困难。我想mabey整个结构都错了? 我可以为1个文件找到正确的路径,但相关文件的数组似乎不起作用

##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
因此:


这似乎是一个完美的使用机会


为什么
$fullpath=escapeshellarg($fulldir$entry”)?只是好奇
$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;
<?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, 
        );
}
?>