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.
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.