检查文件夹中的最后一个 js/css 文件


Check last js/css file in folder

我正在构建一个简单的PHP脚本来组合我所有的站点css/js文件。

我现在想做的是检查"缓存"文件夹中最新构建的 css 或 js 文件。

所以...一些功能,如:

function getLastFile('js'){
   return the js file name
}
function getLastFile('css'){
   return the css file name
}

我在网上找到了有关如何检查某个文件夹中的最后一个文件的解决方案......但是我怎样才能通过特定的扩展名准确检查最后一个呢?

您可以使用 glob 函数。

要获取 js 文件,请使用 glob('cache/*.js'); 和 css glob(cache/*.css);您可以使用文件时间来获取最新修改的文件。

请参阅此问题。

如果你的意思是最后作为most recent built

//get the last-modified-date of this very file
$lastModifiedTime=filemtime($Cachedfile);

或者最好看看智能优化器代码,稍微看看它的源代码,你一定会得到一个想法