【发布时间】:2018-02-05 05:52:52
【问题描述】:
但文件夹中只有 3 张图片正确显示。
<table class="table">
<?php
$dir = '../images/slideshow';
$file_display = array('jpg', 'jpeg', 'png', 'gif');
if (file_exists($dir) == false) {
echo 'Directory \''. $dir. '\' not found!';
} else {
$dir_contents = scandir($dir);
foreach ($dir_contents as $file) {
$ex = explode('.', $file);
$file_type = strtolower(end($ex));
?>
<tr>
<td><img alt="<?php echo $file?>" width="64px" height="64px" src="<?php echo $dir."/".$file?>">
<td class="td" style="text-align: center;"><a href="<?php echo $_SERVER['PHP_SELF']."?action=delete&id=".$row["id"]; ?>" class="btn btn-default btn-danger" >Delete</a><?php
}
}
?>
</table>
编辑: 我可以通过将上面的代码更改为以下代码来解决此问题...
<table class="table">
<?php
$dir = '../images/slideshow';
$file_display = array('jpg', 'jpeg', 'png', 'gif');
if (file_exists($dir) == false) {
echo 'Directory \''. $dir. '\' not found!';
} else {
$dir_contents = scandir($dir);
$file_display = array(
'jpg',
'jpeg',
'png',
'gif'
);
foreach ($dir_contents as $file) {
$ex = explode('.', $file);
$file_type = strtolower(end($ex));
if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true) {
?>
<tr>
<td><img alt="<?php echo $file?>" width="64px" height="64px" src="<?php echo $dir."/".$file?>">
<td class="td" style="text-align: center;"><a href="<?php echo $_SERVER['PHP_SELF']."?action=delete&id=".$row["id"]; ?>" class="btn btn-default btn-danger" >Delete</a><?php
}
}
}
?>
</table>
只检查文件扩展名。
【问题讨论】:
-
检查您的图像名称和这两个图像中使用的文件夹的路径....
-
使用开发者工具检查图片路径。右键单击-> 检查元素
-
同时发布 PHP 代码
-
你的图片文件名中有空格吗?如果是这样,请删除空格
-
你的代码在哪里