Hey all,
I would really appreciate it if you can help me with this problem.
The basic idea, read all the files in a folder, and print them as links to each file.
Which does work.
But now, after it gets out of the foreach loop, I need it to keep the array of $fileNames.
Because I need to reuse it after, but it doesn't. And I don't get why.
Thanks in advance, code is following.
$siteName = 'my site';
$fileNames = array();
$fileNumber = 0;
$directory = 'applications/bussSites';
$dir = new DirectoryIterator($directory);
foreach($dir as $file ){
if(($file != ".") && ($file != "..")){
$fileNames[$fileNumber] = $file;
echo '<a href="'.$siteName.$directory.'/'.$file.'">'.$file.'<a><br />';
$fileNumber++;
}
echo "=".$fileNumber."--".$fileNames[$fileNumber-1]."<br/>";
}
//echo $fileNames[3]."<br/>";
echo "========================\n";
for($i=0; $i<$fileNumber; $i++){
echo $fileNames[$i+1]."<br />";
}
echo "<br />";
echo "<a>Number: ".$fileNumber."</a>";
echo '</div>';
and I get this:
1_aple.txt
=1--1_aple.txt
3_jasd.txt
=2--3_jasd.txt
10_jad.txt
=3--10_jad.txt
7_pdjf.txt
=4--7_pdjf.txt
=4--.
=4--..
2_jdha.txt
=5--2_jdha.txt
========================
Number: 5