PHP获取比1天大的文件,并且文件名以“ a”开头。
因此,我想做的是:
删除文件:
- 如果目录中的文件名以“ A”开头,则检查其是否大于1天。
或者,
- 如果目录中的文件名以“ B”开头,请检查其是否大于1周。
示例:
afilename.jpg(时间戳说该文件已有2天大) - >删除 / UNLINK。
到目前为止,我尝试的是:
<?php
// $files = preg_grep('~^a.*~', scandir("./uploads"));
// I want to combine line 1 & line 3 but I don't know how to do this.
$files = shell_exec('find ./uploads -mmin +1440');
$file = explode("\n",$files);
if(isset($file) && is_array($file))
{
foreach($file as $val)
{
// @unlink($val);
echo "found";
}
}
?>
我希望我要做什么。
提前致谢。 :)
So what I want to do is:
Delete a file:
- If a filename in a directory starts with 'a' then check if it's older than 1 day.
OR
- If a filename in a directory starts with 'b' then check if it's older than 1 week.
Example:
afilename.jpg (timestamp says the file is 2 days old) -> Delete / unlink.
What I tried so far:
<?php
// $files = preg_grep('~^a.*~', scandir("./uploads"));
// I want to combine line 1 & line 3 but I don't know how to do this.
$files = shell_exec('find ./uploads -mmin +1440');
$file = explode("\n",$files);
if(isset($file) && is_array($file))
{
foreach($file as $val)
{
// @unlink($val);
echo "found";
}
}
?>
I hope it is clear what I want to do.
Thanks in advance. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
知道了。
Got it.