Trying to figure out a read a directory of php files and write to another file. It works fine except that the first file is being put last in the file.
Can someone help point me in the right direction to modify my code to put the file names in the proper order? The file name will be different at times but I'm hoping to keep them in the same order they are in the directory.
Thanks Bob
<?php
$dirDestination = "build";
$path = "build/combine";
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ('.' === $file) continue;
if ('..' === $file) continue;
$myfile = fopen("$dirDestination/iframe.php", "a") or die("Unable to open iframe.php file!");
$txt = "<iframe src =\"$file\" width=\"780\" height=\"1100\"> </iframe>
";
fwrite($myfile, $txt);
fclose($myfile);
}
closedir($handle);
echo "Build completed....";
}
?>
It keeps putting the first file last
<iframe src ="item2.php" width="780" height="1100"> </iframe>
<iframe src ="item3.php" width="780" height="1100"> </iframe>
<iframe src ="item4.php" width="780" height="1100"> </iframe>
<iframe src ="item1.php" width="780" height="1100"> </iframe>