如果每个文件的最后修改日期小于或等于今天的日期,则回显图像

发布于 2024-12-13 19:15:13 字数 1121 浏览 4 评论 0原文

这会从我的文件夹中获取图像。

$dirname = "./uploaded_files/";
$images = scandir($dirname);
$ignore = Array(".", "..");
foreach($images as $curimg){

if(!in_array($curimg, $ignore)) {
};

这将获取文件夹中每个文件的最后修改日期。

$result = array();
$folder = ('uploaded_files/');
$handle = opendir($folder);
foreach (glob("$folder/*") as $team){$sort[]= end(explode('/',$team));}

制作一个包含当前目录中文件的数组:

while (false !==($file = readdir($handle)))
{
if ( $file != ".." && $file != "." )
{
$file = "uploaded_files/".$file ;
if (!is_dir($file))
$result[] = $file;
}
}
closedir($handle);

这是我的 IF AND FOR EACH 语句(这是我的问题)!!!

$lastmoddate = (date("Ymd", filemtime($file)));
$todaysdate = (date("Ymd"));

foreach ($result as $file){
if ($lastmoddate <= $todaysdate){
if (strpos($file, "+12:00") !==false){
echo "$file".",".date ("h:i d/m/Y", filemtime($file))."\r\n"."<br/>";

}
}
}

我想做的是“如果文件名包含 +12:00 并且每个文件的最后修改日期小于或等于今天的日期,则回显图像!”但它不起作用。

谁能帮我弄清楚如何重写我的陈述!?

我刚刚开始学习PHP 有人可以帮忙吗!?

谢谢

This gets the Images from my folder.

$dirname = "./uploaded_files/";
$images = scandir($dirname);
$ignore = Array(".", "..");
foreach($images as $curimg){

if(!in_array($curimg, $ignore)) {
};

This gets the last modified dates for each file in the folder.

$result = array();
$folder = ('uploaded_files/');
$handle = opendir($folder);
foreach (glob("$folder/*") as $team){$sort[]= end(explode('/',$team));}

Making an array containing the files in the current directory:

while (false !==($file = readdir($handle)))
{
if ( $file != ".." && $file != "." )
{
$file = "uploaded_files/".$file ;
if (!is_dir($file))
$result[] = $file;
}
}
closedir($handle);

This is my IF AND FOR EACH statement (here is my problem)!!!

$lastmoddate = (date("Ymd", filemtime($file)));
$todaysdate = (date("Ymd"));

foreach ($result as $file){
if ($lastmoddate <= $todaysdate){
if (strpos($file, "+12:00") !==false){
echo "$file".",".date ("h:i d/m/Y", filemtime($file))."\r\n"."<br/>";

}
}
}

what I am trying to do is 'if the file names contain +12:00 and if the lastmodified dates for each file is less or equal to todays date then echo Images! BUT it Doesn't work.

Can anyone help me figure out how to re-write my statement!?

I've just started learning PHP
Can anyone help!?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎樣才叫好 2024-12-20 19:15:13

通过使用 date() 函数,您可以将整数日期转换为人类可读的日期。这样做时,您将无法再比较日期(以您正在使用的 dmy 格式)。

最简单的解决方法是将日期格式从“dm y”更改为“Ymd”,以便可以将其作为数字进行比较。

另外,您提到 moddate 应该小于或等于,但您的代码使用 >=,因此您可能需要更改它。

By using the date() function, you are converting the integer date into a human readable date. In doing this, you will no longer be able to compare the dates (in the d m y format you are using).

The easiest fix would be to change your date format from "d m y" to "Ymd" so that it can be compared as a number.

Also, you mention that the moddate should be less or equal to, but your code uses >=, so you may need to switch that around.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文