PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
What I to be enabled to do is stop certain files from showing. The files that I don't want to be shown is in the disfiles.txt file in this format(One file per line):
$fn = count($file);
$j= 0;
while ($ij < $fn) {
if ($file[$j] == $filecontents[$i] || $file[$j] == "disfiles.txt") {
/// not sure where the $i in $filecontents comes from..
}else {
echo $file[$j]."\n<br>";
}
}
Not sure if thats what you ment...
but you could have the non allowed files in an array which is then sorted...
<?php
$filecontents = file("disfiles.txt");
// elements returned by file() will have trailing linebreaks as they were in the file
// remove them
$filecontents = array_map('trim', $filecontents);
$handle=opendir('.');
while ($file = readdir($handle)) {
if (is_file("./$file") && !in_array($file, $filecontents))
echo $file, "\n<br>";
}
closedir($handle);
?>
(also note the comment)
In PHP Timing Issues jason points out that array_flip/isset is faster than in_array. This still seems to be true for current versions of php and since filenames are unique for one directory you might use
<?php
$filecontents = file("disfiles.txt");
// elements returned by file() will have trailing linebreaks as they were in the file
// remove them
$filecontents = array_flip(array_map('trim', $filecontents));
$handle=opendir('.');
while ($file = readdir($handle)) {
if (is_file("./$file") && !isset($filecontents[$file]))
echo $file, "\n<br>";
}
closedir($handle);
?>