1

I am trying to fix this part of the code as I am getting an error like this:

Warning: filemtime(): stat failed for /var/www/vhosts/example.tk/httpdocs/manager/css/general.css in /var/www/vhosts/example.tk/httpdocs/js-and-css.inc.php on line 49

 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;
        } 

The line 49 is : $time = filemtime($temp_path);

I think this is something related to the path.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Orkhan Orkhan
  • 105
  • 2
  • 8
  • Have you confirmed that the file in the error message, /var/www/vhosts/example.tk/httpdocs/manager/css/general.css, actually does exist? You're setting $temp_path to a new value if one of the files doesn't existing, but there's no subsequent check to see if the new file exists. – Virtually Nick Feb 22 '18 at 18:13
  • In everywhere the file named general.css is called not in there but here : /var/www/vhosts/example.tk/httpdocs/merchant/css/general.css so I mean the file is not exists there but I wonder how can I do that it calls not the file which exists there , instead under merchant folder. – Orkhan Orkhan Feb 22 '18 at 18:18

1 Answers1

1

To get around the specific problem you're having, you'd need to do this:

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;
        }
    }

The if(file_exists($tempfile)) block will prevent filemtime() from getting called on a file that does not exist. As to your question in the comment above about how to get the file in the merchant/css directory instead of manager/css, I don't know the answer to that - the code you provided does not give enough detail about how the file list is generate (passed in through the $arr_css variable), so more detail would be required to figure out why a file is being passed in that does not exist.

Virtually Nick
  • 358
  • 2
  • 8