【问题标题】:Warning: filemtime(): stat failed in line 49警告:filemtime(): stat 在第 49 行失败
【发布时间】:2018-02-22 17:57:44
【问题描述】:

我正在尝试修复这部分代码,因为我收到如下错误:

警告:filemtime(): stat failed for /var/www/vhosts/example.tk/httpdocs/manager/css/general.css in /var/www/vhosts/example.tk/httpdocs/js-and-第 49 行的 css.inc.php

 function addStyleCssHtml($arr_css){
$css_files=implode('|', $arr_css);
$file_hash=sha1($css_files);
$dest_path=$_SERVER['DOCUMENT_ROOT'].'/css/static-'.$file_hash.'.css';
$recreate=!file_exists($dest_path);    
if (!$recreate) {
    $last_updated=filemtime($dest_path);
    foreach ($arr_css as $fl){
        $temp_path=(substr($fl, 0, 1)=='/')?$_SERVER['DOCUMENT_ROOT'] . $fl:realpath($fl);
        if (!file_exists($temp_path)) $temp_path=$_SERVER['DOCUMENT_ROOT'].'/'.$fl;
        $time = filemtime($temp_path);
        if ($time > $last_updated) {
           $recreate=true;
           break;
        } 

第 49 行是:$time = filemtime($temp_path);

我认为这与路径有关。

【问题讨论】:

  • 您确认错误消息中的文件 /var/www/vhosts/example.tk/httpdocs/manager/css/general.css 确实存在吗?如果其中一个文件不存在,您将 $temp_path 设置为一个新值,但没有后续检查新文件是否存在。
  • 在任何地方,名为 general.css 的文件都没有被调用,而是在这里:/var/www/vhosts/example.tk/httpdocs/merchant/css/general.css 所以我的意思是文件是那里不存在,但我想知道我该怎么做,它调用的不是那里存在的文件,而是在商家文件夹下。

标签: php stat filemtime


【解决方案1】:

要解决您遇到的具体问题,您需要这样做:

if (!$recreate) {
$last_updated=filemtime($dest_path);
foreach ($arr_css as $fl){
    $temp_path=(substr($fl, 0, 1)=='/')?$_SERVER['DOCUMENT_ROOT'] . $fl:realpath($fl);
    if (!file_exists($temp_path)) $temp_path=$_SERVER['DOCUMENT_ROOT'].'/'.$fl;
    if (file_exists($temp_path)) {
        $time = filemtime($temp_path);
        if ($time > $last_updated) {
           $recreate=true;
           break;
        }
    }

if(file_exists($tempfile)) 块将防止filemtime() 被调用一个不存在的文件。至于您在上面的评论中关于如何在商人/css 目录而不是 manager/css 中获取文件的问题,我不知道答案 - 您提供的代码没有提供有关文件列表如何的足够详细信息是生成的(通过 $arr_css 变量传入),因此需要更多细节来弄清楚为什么传入的文件不存在。

【讨论】:

  • @OrkhanOrkhan 您可以通过接受答案将问题标记为已解决。这将表明问题已解决。
  • 我无法将问题标记为已解决。你能告诉我怎么做吗?
猜你喜欢
  • 1970-01-01
  • 2012-11-03
  • 1970-01-01
  • 2011-10-30
  • 2013-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-28
相关资源
最近更新 更多