0

I am building up a simple PHP script to get all my site css/js files combined.

What I would like to do now is checking for the most recent built css or js file in the "cache" folder.

So... some function like:

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

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

I've found out solutions on the net on how to check for the last file in some folder... but how can I exactly check the last by a specific extension?

000
  • 26,951
  • 10
  • 71
  • 101
user2840318
  • 1,047
  • 2
  • 9
  • 14

2 Answers2

1

You can use the glob function.

For getting the js files, use glob('cache/*.js'); and for css glob(cache/*.css); And you can use filetime to get the latest modified file.

Refer to this question.

Community
  • 1
  • 1
varun1505
  • 800
  • 2
  • 8
  • 16
0

if u mean last as most recent built

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

or better have a look over the smartoptimizer Code , have a tiny look through its source u will surely get an idea

internals-in
  • 4,798
  • 2
  • 21
  • 38