Every time a page loads with a static resource referenced on it, this error generates in the error log.
(ERROR @ /long_file_path/public_html/core/model/modx/modstaticresource.class.php : 93) PHP warning: filesize(): stat failed for files/css/{filename}.css
Here's the relevant method from modstaticresource class as well:
class modStaticResource extends modResource implements modResourceInterface {
/** ... **/
/**
* Get the absolute path to the static source file represented by this instance.
*
* @param array $options An array of options.
* @return string The absolute path to the static source file.
*/
public function getSourceFile(array $options = array()) {
$filename = (string)parent::getContent($options);
// Support placeholders/snippets in the filename by parsing it through the modParser
$array = array();
if ($this->xpdo->getParser() && $this->xpdo->parser->collectElementTags($filename, $array)) {
$this->xpdo->parser->processElementTags('', $filename);
}
// Sanitize to avoid ../ style path traversal
$filename = preg_replace(array("/\.*[\/|\\\]/i", "/[\/|\\\]+/i"), array('/', '/'), $filename);
// If absolute paths are allowed (disabled by default for security reasons), and a file exists at the provided path, use it
$allowAbsolute = (bool)$this->xpdo->getOption('resource_static_allow_absolute', null, false);
if ($allowAbsolute && file_exists($filename)) {
$this->_sourceFile = $filename;
$this->_sourceFileSize = filesize($filename);
}
// If absolute paths are **not** allowed or an absolute file was not found, prefix the resource_static_path setting
else {
$sourcePath = $this->xpdo->getOption('resource_static_path', $options, '{assets_path}', true);
if ($this->xpdo->getParser() && $this->xpdo->parser->collectElementTags($sourcePath, $array)) {
$this->xpdo->parser->processElementTags('', $sourcePath);
}
// If an absolute path was provided that matches the required path, strip the absolute portion as it's added again below
if (strpos($filename, $sourcePath) === 0) {
$filename = substr($filename, strlen($sourcePath));
}
// When selecting a file using the media browser, that will provide a relative url like "assets/static/foo.pdf";
// To avoid that from 404ing when the resource_static_path is set to {assets_path}, we need to check
// if the provided $filename starts with the _relative_ url, matching against the base path.
// This doesn't work for directories outside of the base path (ie a moved core), but that's too complex
// to resolve without full media source support on static resources.
$relativeSourcePath = strpos($sourcePath, MODX_BASE_PATH) === 0 ? substr($sourcePath, strlen(MODX_BASE_PATH)) : false;
// if $filename starts with the $relativeSourcePath, remove the $relativeSourcePath from the start of $filename
// to avoid that getting duplicated when adding the $sourcePath below.
if ($relativeSourcePath && strpos($filename, $relativeSourcePath) === 0) {
$filename = substr($filename, strlen($relativeSourcePath));
}
$this->_sourceFile = $sourcePath . $filename;
if (file_exists($this->_sourceFile)) {
// Line 93
$this->_sourceFileSize = filesize($filename);
}
}
return $this->_sourceFile;
}
/** ... **/
}
All of the files referenced in the error log, files/css/{filename}.css
, are all inside the assets/
directory.
Originally, I thought it was only happening with font files, .woff
and .woff2
, but it is now any file that a static resource is created for.
Each static resource uses a template that is just:
[[*content]]
I haven’t used any snippets or plugins to alter the content of the files, and have double checked them for strange characters. I also double checked content-types (referencing the font files). I am able to see the file if I view the static resource, as well as just by going to the asset path for the file.
Since it was just a PHP warning I didn’t think much of it, but I opened the error log today and it was over 5mb, so it was time to deal with it.
Any ideas?