所有文件使用列表中的symfony我試圖創建列出所有圖像在Web文件夾頁目錄中的
我創建了以下行動:
$dir = 'images/blog';
$fulldir = "{$_SERVER['DOCUMENT_ROOT']}/$dir";
$d = @dir($fulldir) or die('Failed opening directory for reading');
while(false !== ($entry = @$d->read()))
{
$this->imagesBlog[] = array(
"file" => "/$dir/$entry",
"size" => getimagesize("$fulldir/$entry"));
$d->close();
}
而下面的模板:
foreach($imagesBlog as $img)
echo '<img class="photo" src="'.$img['file'].'" ' . $img['size'][3].'>'."\n";
這似乎工作,但只返回包含多個文件的文件夾中的一個圖像。
print_r($imagesBlog):
sfOutputEscaperArrayDecorator Object
(
[count:sfOutputEscaperArrayDecorator:private] => 1
[value:protected] => Array
(
[0] => Array
(
[file] => /images/blog/FM-stupidest.png
[size] => Array
(
[0] => 300
[1] => 252
[2] => 3
[3] => width="300" height="252"
[bits] => 8
[mime] => image/png
)
)
)
[escapingMethod:protected] => esc_specialchars
)
幫助!我在這裏放鬆心情。
這是至少四次。請在http://stackoverflow.com/search?q=list+all+files+in+a+directory+php – Gordon 2011-01-21 13:58:14
找到您的答案[PHP列出目錄中的所有文件](http://stackoverflow.com/questions/3826963/php-list-all-files-in-directory) – Gordon 2011-01-21 13:58:41