<?php
$url = 'http://localhost/img';
$dir = 'C:\Program Files\Apache Group\Apache2\htdocs\img';
$max = 5;
//$images = preg_grep('/\.(?:jpe?g|gif|png)\z/i', scandir($dir));
$images = array(
'a.jpg',
'b.GIF',
'C.png',
'd.JPEg',
'a.jpg',
'b.GIF',
'C.png',
'd.JPEg',
'a.jpg',
'b.GIF',
'C.png',
'd.JPEg',
);
array_walk($images, function (&$v) {
$v = $url . $v;
});
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<h1><?=$dir?>内の画像一覧</h1>
<?php if (!$images): ?>
<p>表示する画像はありません</p>
<?php else: ?>
<table>
<tr>
<?php foreach ($images as $i => $img): ?>
<?php if ($i !== 0 && $i % $max === 0): ?>
</tr>
<tr>
<?php endif; ?>
<td><img src="<?=$img?>"></td>
<?php endforeach; ?>
</tr>
</table>
<?php endif; ?>
</body>
</html>
preferences:
42.83 ms | 402 KiB | 5 Q