filemtime“警告统计失败" [英] filemtime "warning stat failed for"

查看:108
本文介绍了filemtime“警告统计失败"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多关于它的问题和答案,但是我仍然无法解决我的问题...

I already read it so many questions and answers about it but I can't still solve my problem...

我正在尝试创建一个函数来删除一天前创建的所有带有"xml"或"xsl"扩展名的文件.但是我在拥有的每个文件上都收到此警告:

I'm trying to create a function that deletes all the files with "xml" or "xsl" extension that has been created one day ago. But I'm getting this warning on each file I have:

警告:filemtime()[function.filemtime]:第44行/home/u188867248/public_html/ampc/library.php中的post_1003463425.xml统计信息失败

Warning: filemtime() [function.filemtime]: stat failed for post_1003463425.xml in /home/u188867248/public_html/ampc/library.php on line 44

此目录中的所有文件都具有相同的结构名称"post_ + randomNum + .xml"(例如:post_1003463425.xml或post_1456463425.xsl).因此,我认为这不是一个编码问题(就像我在其他问题中看到的那样).

All the files of this directory have the same structure name "post_ + randomNum + .xml" (example: post_1003463425.xml or post_1456463425.xsl). So I think it's not an encoded problem (like I saw in other questions).

我的函数的代码是这样的:

The code of my function is this:

 function deleteOldFiles(){
    if ($handle = opendir('./xml')) {
        while (false !== ($file = readdir($handle))) { 

            if(preg_match("/^.*\.(xml|xsl)$/i", $file)){

                $filelastmodified = filemtime($file);

                if ( (time()-$filelastmodified ) > 24*3600){
                    unlink($file);
                }
            }
        }
        closedir($handle); 
    }
}

感谢您的帮助:)

推荐答案

我认为问题在于文件的真实路径.例如,您的脚本在'./'上运行,文件在目录'./xml'内.因此,在获取filemtime或取消链接之前,最好检查文件是否存在:

I think the problem is the realpath of the file. For example your script is working on './', your file is inside the directory './xml'. So better check if the file exists or not, before you get filemtime or unlink it:

  function deleteOldFiles(){
    if ($handle = opendir('./xml')) {
        while (false !== ($file = readdir($handle))) { 

            if(preg_match("/^.*\.(xml|xsl)$/i", $file)){
              $fpath = 'xml/'.$file;
              if (file_exists($fpath)) {
                $filelastmodified = filemtime($fpath);

                if ( (time() - $filelastmodified ) > 24*3600){
                    unlink($fpath);
                }
              }
            }
        }
        closedir($handle); 
    }
  }

这篇关于filemtime“警告统计失败"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆