我有一個腳本,通過具有3個圖像PHP使用目錄中的文件
$imglist='';
$img_folder = "path to my image";
//use the directory class
$imgs = dir($img_folder);
//read all files from the directory, checks if are images and ads them to a list
while ($file = $imgs->read()) {
if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
$imglist .= "$file ";
}
closedir($imgs->handle);
//put all images into an array
$imglist = explode(" ", $imglist);
//display image
foreach($imglist as $image) {
echo '<img src="'.$img_folder.$image.'">';
}
但我有是顯示第四IMG無圖像的問題目錄不用..但我只有3該文件夾中的圖像。
測試你的代碼文件名爲「this_is_text_not_png.txt」 – horatio