I actually wrote a script just for a purpose like this in one of the open source projects im working on.
I wanted to make a semi-command line interface for displaying files in a folder.
You can use this code, and just modify what you need. This only lists files from the directory specified by $folder though.
Code: Select all
<?php
# List Files Console Command
function listFiles($server,$folder){
if(!isset($server) || !isset($folder)){
return false;
}else{
//----------------------------------------------
// Open the specified SERVER FILE STRUCTURE file
$file = "{$server}.sfs";
$file_handle = fopen($file, "r");
$file_contents = fread($file_handle, filesize($file));
fclose($file_handle);
$sfs = explode("\n", $file_contents);
// Store SFS into an array and close file
//----------------------------------------------
// Go through the file and remove any commented lines
foreach($sfs as $row){
if(strpbrk($row,"#")){
array_splice($sfs,0,1);
}
}
// remove the blank line remaining
array_splice($sfs,0,1);
// Go through each line in the file and look
// for the matching directory. Once found,
// split the files in that directory into
// an array.
foreach($sfs as $dir){
if(substr($dir,0,3)==$folder){
//remove the first 4 characters
// they are folder data
$dir = substr_replace($dir,"",0,4);
//remove the last 3 characters
// they finish the line.
$dir = substr_replace($dir,"",strlen($dir)-3);
//add all the files in the directory into an array
// using the : delimiter
$files = explode(":",$dir);
}
}
$newFileArray = array();
array_push($newFileArray,"Files in directory: {$folder}\n");
foreach($files as $file){
array_push($newFileArray,"-> {$file}\n"); // add file name to array( -> filename.txt ) you could add a link here
}
return $newFileArray;
}
}
?>
This is an example of the file structure.
The name of the file is <ServerName>.sfs
Code: Select all
# ServerName.sfs
sys[kernel.sys:os.sys:accounts.sys:security.sys:crcdisk.sys];
usr[admin];
pub[data-Nin-115589:data-Nin-01559:app-Nin-22234];
log[log.dat];
bin[];
Using that, should give you a print out of the input $folder located in the input $server file.
From there you could change the code slightly where i mentioned you could add a link in, then send that to a php page which loads the data from file <filename> which would be located in your $_GET or $_POST if you wanted a little more work.
Also, this is how you use the above function:
Code: Select all
$fileList= listFiles($currentServer,$currentFolder);
foreach($fileList as $file){
print "{$file}";
}
But if you stored all your servers in a single file, then you could change the opening of the file from a variable to a set file, then do a check on the server and folder rather than just the folder.