lista plików z folderu w postaci html
April 7th, 2010
Comments off
przydatne jeśli chcemy na szybko wygenerować sobie listę wszystkich plików z katalogu i opakować w #filename
/**
* creating list.txt
* ls > list.txt
*/
//const input output file
define('__INPUT_FILE__', "list.txt");
define('__OUTPUT_FILE__', "lista.html");
//wrapper for each line of input file
define('__PRE__','<a href="');
define('__MIDDLE__','">');
define('__SUFFIX__','</a><br/>');
//read input file into array
$list = file(__INPUT_FILE__);
//open output file to write and set pointer at the end of file
//if file does no exist attempt to create one
$file = fopen(__OUTPUT_FILE__, "a+");
//write each line into file into wrapper const
foreach($list as $value)
{
$output = __PRE__ . $value . __MIDDLE__ . $value . __SUFFIX__;
fwrite($file, $output);
}
//close file after finished
fclose($file);