编辑 -
我能够解决这个问题但是我只想显示在我的目录中找到的.png文件。有没有办法只通过在此代码中添加内容来显示png文件?
<?php
$path = 'testimages';
$handle = @opendir('./' . $path . '/');
while ($file = @readdir($handle)){
if("." === $file || ".." === $file) continue;
echo ', {' . "\n" . ' id: ' . preg_replace("#\.[^\.]+$#", "", $file) . ',' . "\n" . 'name: "Product ' . preg_replace("#\.[^\.]+$#", "", $file) . '",' . "\n" . 'imageUrl: "' . $file . '",' . "\n" . 'thumbnailUrl: "' . $file . '",' . "\n" . 'openUrl: "' . preg_replace("#\.[^\.]+$#", "", $file) . '.html"' . "\n" . '}' . "\n";
}
@closedir($handle);
unset($handle,$file,$path);
?>