<?php
$myDirectory = opendir("uploads");
// get each entry
while(false !== ($entryName = readdir($myDirectory))) {
if ($entryName != "." && $entryName != "..") {
$dirArray[] = $entryName;
}
}
// close directory
closedir($myDirectory);
// count elements in array
$indexCount = count($dirArray);
Print ("$indexCount files<br>\n");
// sort
sort($dirArray);
// print
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
print("<TR><TH>Filename</TH></TR>\n");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden
files
print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a>
</td>");
print("</TR>\n");
}
}
print("</TABLE>\n");
?>
I can see the list of files but when i click any of the file , it show me object not found. Anyone knows what the problem in the codes? Thank you
Because you not open the files in right folder. Trying to give your folder front of filename. Here your code:
print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a>
And correctly is
print("<TR><TD><a href=\"uploads/$dirArray[$index]\">$dirArray[$index]</a>