thanks only problem i have is just getting the files to show for some reason its not showing, But i appreciate the help.
get files from a folder
perhaps you could show us what you did with the code. did you change the path so that it points to the folder you'd like to list?
thats what I did
<?php
$the_path = 'public_html/lounge/feat';
if ($handle = opendir($the_path)) {
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}
?>
If you have the script you posted in your public_html (web) directory or a directory under that one then the path you give is wrong. It should be, in the first case, 'lounge/feat' or, in either case, $_SERVER['DOCUMENT_ROOT'] . 'lounge/feat'. And if you don't get a message telling you that the path is invalid (thus telling you immediately what the problem is), it's because you don't have error_reporting enabled.
So if you got errors, you should ALWAYS post them here. It's really helpful to know what exactly "isn't working" means.
Try this modified one...it might help you figure out what your path should be by reporting some information. It also displays an error message if you can't open your path.
<?php
// it might be helpful to know where the current file is located
// in order to properly enter the path of your directory:
echo 'THIS FILE:' . __FILE__ . '<br>';
// since you gave a relative path rather than an absolute path
// it is going to be evaluated relative to this path location:
echo 'the current working directory is ' . getcwd() . '<br>';
$the_path = 'public_html/lounge/feat';
if ($handle = opendir($the_path)) {
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
} else {
echo 'UNABLE TO OPEN ' . $the_path . '<br>';
}
?>
Ok so this is what happens:
http://a.parsons.edu/~dpaul/lounge/featured.php
It gets the directory and everything.
Well hooray.
Thanks now i just have to figure out how to just get the html files and is it possible to have the last one posted at the top?.
theprofession wrote:how to just get the html files
Sounds like you want to use [man]glob[/man] instead of [man]opendir/man/[man]readdir/man with a pattern like ".html" (or, if you have both .html and .htm files, ".{htm,html}" with the GLOB_BRACE flag).
theprofession wrote:is it possible to have the last one posted at the top?
It most certainly is. In fact, one user contributed a function that does exactly this.
<?php
foreach (glob("*.txt") as $filename) {
echo "$filename size " . filesize($filename) . "\n";
}
?>
when I use this it doesnt goto the next line in the output...
Are you sure? If you're viewing the results in a browser, try viewing the source code of the page - I bet you'll see the new lines you're looking for.
theprofession wrote:
<?php foreach (glob("*.txt") as $filename) { echo "$filename size " . filesize($filename) . "\n"; } ?>
when I use this it doesnt goto the next line in the output...
Ok i change this up a bit and got it to work just trying to get the last modified to appear at the top. So I am messing around with the function.
bradgrafelman wrote:Are you sure? If you're viewing the results in a browser, try viewing the source code of the page - I bet you'll see the new lines you're looking for.
I'm not sure but i changed up the code instead of using "/n" i used br to replace it.
If you're still having trouble getting the last modified file at the top, have you followed the link I posted back in February?