如何在PHP中显示目录中的图像?
我正在尝试显示一组来自本地目录的图像,以及创建的大小和日期。我尝试了这个方法,但似乎不起作用如何在PHP中显示目录中的图像?,php,web,directory,Php,Web,Directory,我正在尝试显示一组来自本地目录的图像,以及创建的大小和日期。我尝试了这个方法,但似乎不起作用 <?php $dir = "./images"; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { echo "<img src='/images/$file'>"; echo
<?php
$dir = "./images";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false)
{
echo "<img src='/images/$file'>";
echo date (Y/m/d H: i, filemtime($file));
echo filesize($file);
}
closedir($dh);
}
}
?>
文件时间和文件大小出现一些错误
<?php
$dir = "./images";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false)
{
echo '<img src="'. $dir. '/'. $file. '" alt="'. $file. '" />';
echo date ('Y/m/d H:i',filemtime($dir. '/'. $file));
echo filesize($dir. '/'. $file)." bytes";
}
closedir($dh);
}
}
?>
您是否已打开错误报告功能
Y/m/d H:i
您的字符串日期格式没有引用为字符串。这应该会产生一个错误。另外,您忘记在filemtime
和filesize
中连接$dir
<?php
$dir = "./images";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false)
{
echo '<img src="'. $dir. '/'. $file. '" alt="'. $file. '" />';
echo date ('Y/m/d H:i',filemtime($dir. '/'. $file));
echo filesize($dir. '/'. $file)." bytes";
}
closedir($dh);
}
}
?>