stat failed filemtime() Codeigniters assetlib-pro on a plesk server
I came across this error when I was trying to implementing the Assetlib-pro CodeIgniter library for adding assets etc to your project.
A PHP Error was encountered
Message: filemtime() [function.filemtime]: stat failed for
Line Number: 218
Now because of my setup from EukHost in the uk I use plesk as my admin system, which obviously has custom rules etc for how php and apache behave together and how they are setup. For some reason the assetlib code could correctly get to the styles I had defined in the assetlib config file – ‘/assets/’, but I had to manually change a line of code in the assetlib library file.
$mtimes = filemtime(dirname(FCPATH).'/'.trim($asset,'/'));
$mtimes = filemtime(dirname(FCPATH).'/httpdocs/'.trim($asset,'/'));
For some reason when the function filemtime went to do its thing it would try and run the function of this location ‘/var/www/vhosts/domain.com/assets/styles_1.css’ which is wrong as you can see its missing the ‘httpdocs’ after the domain name. I did change my assetlib config file to ‘/httpdocs/assets/’ but that didn’t work at all, the code seems to me to be wrong. However when i changed the code this fixed that specific problem and i can now use the library as it is intended, however I still can’t manage to get the compression aspect of the library working yet, I havent looked into yet but i’m guessing its just a pathing issue again.
Anyway I hope this can help people that have a similar setup to me, or are having the same issue.
Rough outline of my current setup:
- Running centos-5-x86
- Running PHP 5
- Running Plesk 9.3.0
I took a look at this code too, using your blog post for help. The change you made will mean that the library will need to be modified between the dev and live servers.
Note the line: $mtimes = filemtime(dirname(FCPATH).’/’.trim($asset,’/’)); in the code includes dirname(FCPATH).
Well, the dirname of FCPATH in most cases will be the parent of the true directory (try outputting FCPATH and dirname(FCPATH)).
So, the fix I have applied is as follows:
$mtimes = filemtime(FCPATH.’/’.trim($asset,’/’));
I hope that helps.
Excellent Kurucu! Confirmed working, no more hacky code 🙂