Can anyone tell me the best practice for including a set of files in a directory?
For instance, if I had a directory that was /javascript, and in there it had 10 javascript files, how would I go about loading the entire directory?
This question is moot now, but for future reference;
I use the following to read files in the same manner:
<?php
session_start();
// Auto import all js files in the directory.
$files = glob("*.js");
sort($files);
$jsFiles = array();
for($i = 0; $i < count($files); $i++){
error_log('Auto-Opening: '.$files[$i]);
$tempString = file_get_contents($files[$i]);
//error_log('Auto-Opened Content: '.$tempString);
array_push($jsFiles, $tempString);
}
?>
Sorry, I guess this needs clarification:
The code I have included is used in an entirely seperate part of my project, it includes the RAW string format of a directory of javascript files for my processing purposes. You do not have to worry about why I am doing this.
I could use this to add script
tags, and echo these files, but I am looking for a faster more elegant way to include a directory. Unlike the code above (whose javascript never gets executed by my code. I simply create the string from the files and send it to JS for parsing).
Please also note, as suggested:
$files = glob("{directory/*.js}",GLOB_BRACE);
for($i = 0; $i < count($files); $i++){
include($files[$i]);
}
Does nothing but echo those files to the screen, without script
tags.