<?php
$directory = "/jobops";
$contents = scandir($directory);
if ($contents) {
foreach($contents as $key => $value) {
if ($value == "." || or $value == "..") {
unset($key);
}
}
}
echo "<ul>";
foreach($contents as $k => $v) {
echo "<li><a href=\"$directory/" . $v . "\">link text</a></li>";
}
echo "</ul>";
?>
Should work. Takes the directory, scans it, maps all the filenames into an array $contents
removes the relative urls (the "." and "..") and then echoes them out.
Remember that foreach
is relatively expensive, though; so you may wish to simply unset $contents[0]
and $contents[1]
.
Edited in response to the following (from the OP):
Warning:
scandir(www.markonsolutions.com/jobops)
[function.scandir]: failed to open
dir: No such file or directory in
/home/content/t/i/m/timhish/html/test.php
on line 5 Warning: scandir()
[function.scandir]: (errno 2): No such
file or directory in
/home/content/t/i/m/timhish/html/test.php
on line 5 Warning: Invalid argument
supplied for foreach() in
/home/content/t/i/m/timhish/html/test.php
on line 15 I changed ti from "/jobops"
thinking it was a relative directory
thing but apparently that's not it. also
im not sure what the
/home/content....... thing is but i am
currently hosted with go daddy maybe
thats how they store things?
The $directory
variable is relative to where the script is being called. In my case, this runs from the root folder so it should be, for me, $directory = "jobops"
assuming the folder and script are stored in the same place. Without knowing your server's directory structure I can't really help you, but I would suggest ruling out a problem with the scandir()
function.
To do this, create a folder in the same directory as your script called whatever you like, populate it with at least one image (so that the following if()
doesn't unset the entire array) and see if that works. If it does then you're stuck with finding the relative path to your folder. If it doesn't then I'm stuck myself.