【发布时间】:2021-06-10 18:43:04
【问题描述】:
我在图片上传页面中添加了图片,并在另一个网页中显示图片和缩略图。我将调整大小名称与 time() 函数一起使用。我想要这个:我希望我添加的每个图像都按照我刚刚给出的名称按顺序出现在 html 页面上。然而,当我用我写的代码添加照片时,我的 html 页面中的顺序被扭曲了,但我总是希望它按照我添加的顺序继续。如何在我的 html 页面上按顺序显示我使用 Time() 函数重命名的图片?
home.php
<div class ="gallery-items">
<?php
$image_extensions = array("png","jpg","jpeg","gif");
$dir = 'image/';
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
if($file != '' && $file != '.' && $file != '..'){
$thumbnail_path = "image/thumbnailkamu/".$file;
$image_path = "image/".$file;
$thumbnail_ext = pathinfo($thumbnail_path, PATHINFO_EXTENSION);
$image_ext = pathinfo($image_path, PATHINFO_EXTENSION);
if (array_key_exists('delete_file', $_POST)) {
$filen = $_POST['delete_file'];
if (file_exists("image/".$filen)){
unlink("image/".$filen);
unlink("image/thumbnailkamu/".$filen);
}
}
if(!is_dir($image_path) &&
in_array($thumbnail_ext,$image_extensions) &&
in_array($image_ext,$image_extensions)){
?>
<div class ="item">
<a href="<?= $image_path; ?>" data-lightbox="mygallery">
<img src="<?= $thumbnail_path; ?>">
</a>
<a class="btn btn-primary" href="<?= $image_path; ?>" download>Download</a>
<form action = "" method="post">
<input type="hidden" value="<?= $file; ?>" name="delete_file" />
<input class = "button" type="submit" value="Delete" />
</form>
</div>
<?php
}
}
}
}
closedir($dh);
}
?>
</div>
【问题讨论】:
-
这能回答你的问题吗? sort files by date in PHP
-
我希望图像按照我添加它们的顺序出现在 html 页面上。当我尝试使用 sort() 函数修复我自己的代码时,我破坏了代码并且它没有显示任何结果。如何将 sort() 函数集成到我的代码中?谢谢。
标签: php html image-gallery