<?php
$dir = "jb/";
$file_array = scandir($dir);
foreach ($file_array as $file){
echo $file . "<br />";
}
?>so this will list every single file in the DIR, if you have noticed there are 2 extra little guys in there, the dots, those are directory placements, .. means up a dir and . means current dir.so how do we get rid of them? If we try to replace the dots with a null character or a space that screws up the .jpg or .html
<?php
$dir = "jb/";
$file_array = scandir($dir);
foreach ($file_array as $file){
$file = $dir . $file;
if(is_file($file)){
echo $file . "<br />";
}
}
?>we will concatenate $dir to $file, because $file alone will not output the actual file location, you can later strip the $dir for output but i left it so i could use it as a <img src="">deal :)
hopefully this wasn't a waste of space, and it helps some people out!


Sign In
Create Account


Back to top









