【发布时间】:2017-02-08 08:12:23
【问题描述】:
嗨,我设法在 php 上创建了一个图像显示页面,它可以工作,唯一的问题是它显示损坏的图像以及图像 url 仅显示文件夹路径。我的代码在下面,带有最后一页的屏幕截图。有什么我做错了吗?
<form method='post' action='display_images.php'
enctype='multipart/form-data'>
<div class="panel-body">
<div id="tab-4" class="tab-pane">
<div class="table-responsive">
<table class="table table-bordered table-stripped">
<?php
echo <<<_END
<thead>
<tr>
<th>
Image preview
</th>
<th>
Image url
</th>
<th>
Actions
</th>
</tr>
</thead>
_END;
$folder = "../inventory_images";
$filesInFolder = new DirectoryIterator($folder);
while($filesInFolder->valid()){
$file = $filesInFolder->current();
$filename = $file->getFilename();
$src = "$folder/$filename";
$extension = $file->getExtension();
$extension = strtolower($extension);
if ( $extension === 'jpg' || 'png'){
$href = "display_images.php?delete-image=$src";
$img = "<td><img src='$src' height = '100px' width = '100px'></td>";
$input = "<td><input type='text' class='form-control' disabled value='$src'></td>";
}
$filesInFolder->next();
echo"<tbody>";
echo "<tr>";
echo"$img";
echo"$input";
echo"<td><a href='$href' class='btn btn-white'><i class='fa fa-trash'></i></a></td>";
echo"</tr>";
echo"</tbody>";
}
echo <<<_END
</table>
</div>
</div>
</div>
</form>
_END;
?>
这是最终的截图,你可以看到只有一张图片是正确的,前两张是不存在的。 Screenshot containing broken image
【问题讨论】:
-
你想怎么样?