/ Published in: PHP
To make an image browser, add these lines:
$ext = strtolower(substr("$dirArray[$index]", strrpos("$dirArray[$index]", '.') + 1)); //get file extensions
if ("$ext" == "jpg") { // if file is a jpg
print("$dirArray[$index]<a href=\"$dirArray[$index]\"></a>"); // show image and create link to it
$ext = strtolower(substr("$dirArray[$index]", strrpos("$dirArray[$index]", '.') + 1)); //get file extensions
if ("$ext" == "jpg") { // if file is a jpg
print("$dirArray[$index]<a href=\"$dirArray[$index]\"></a>"); // show image and create link to it
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// open this directory // get each entry $dirArray[] = $entryName; } // close directory // count elements in array Print ("$indexCount files<br>\n"); // sort 'em // print 'em print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n"); print("<TR><TH>Filename</TH><th>Filetype</th><th>Filesize</th></TR>\n"); // loop through the array of files and print them all for($index=0; $index < $indexCount; $index++) { print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>"); print("<td>"); print("</td>"); print("<td>"); print("</td>"); print("</TR>\n"); } } print("</TABLE>\n");
URL: http://www.liamdelahunty.com/tips/php_list_a_directory.php