试图找出读取php文件的目录并写入其他文件。它工作正常,除了第一个文件放在文件的最后。读取目录并将文件列表写入文件
有人可以帮助指向正确的方向来修改我的代码,以正确的顺序将文件名?文件名有时会有所不同,但我希望保持它们在目录中的顺序。
感谢 鲍勃
<?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>\n";
fwrite($myfile, $txt);
fclose($myfile);
}
closedir($handle);
echo "Build completed....";
}
?>
它不断把最后的第一个文件
<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>
工作非常好,谢谢。我整天都在尝试很多不同的方式。 – bpross 2014-09-06 21:40:50
我很高兴bpross。 – Joseph8th 2014-09-06 21:51:31