Hi,
I'm trying to generate a page via fopen() & fwrite(). I'm getting the page opened and am able to write two of three variables, but am not getting the third-
In the code below, everything's working, but I'm not getting the result I need- (I'm sure I'm just not asking for the right thing) I'm trying to write a list of files in a directory to a new file. I was hoping to store the result of the function "list_files()" as a variable, but that doesn't seem to be working.
Can you please show me where I'm going wrong?
here's the code:
<?php
// cycle through files in a directory and write image file names as js array
function list_files($folder){
$i = '1';
if ($handle = opendir($folder)) {
while (false !== ($f = readdir($handle))) {
if ($f != '.' && $f != '..') {
$grep = ereg('DS_Store$|php$|html$|htm$',$f);
if (!$grep) {
echo "theImages[$i] = '$f';\n";
$i++;
}
}
}
closedir ($handle);
}
}
// write an include to file that pulls in first x lines
$index_top = "<?php include '../clickthrough-start.inc'?>\n";
// write the js array built with list_files() ||| THIS ISN'T WORKING |||
$index_middle = list_files($dest_folder_name);
// write an include to file that pulls in last x lines
$index_bottom = '<?php include "../clickthrough-stop.inc"?>';
// concatenate all three vars
$index_content = $index_top.$index_middle.$index_bottom;
// open the file
$index_file = fopen($destination_parent_dir.$dest_folder_name.'/index.php','w');
// write the content
fwrite($index_file, $index_content);
?>