Warptweet Posted January 19, 2007 Share Posted January 19, 2007 Here is my code for listing all files in a directory...[code]<?//define the path as relative$path = "/home/yoursite/public_html/whatever";//using the opendir function$dir_handle = @opendir($path) or die("Unable to open $path");echo "Directory Listing of $path<br/>";//running the while loopwhile ($file = readdir($dir_handle)) { echo "<a href='$file'>$file</a><br/>";}//closing the directoryclosedir($dir_handle);?> [/code]How can I...A)Only show .php filesB)Hide the .php part in the file name from viewers. Link to comment https://forums.phpfreaks.com/topic/34824-directory-listing/ Share on other sites More sharing options...
kevinkorb Posted January 19, 2007 Share Posted January 19, 2007 In here...while ($file = readdir($dir_handle)) { echo "<a href='$file'>$file</a><br/>";}change to [code=php:0]while($file = readdir($dir_handle)){ if(substr($file, -4) == '.php') { $length = strlen($file); echo substr($file, 0, ($length-4)); }}[/code]Or that should be close at least... I didn't test. Link to comment https://forums.phpfreaks.com/topic/34824-directory-listing/#findComment-164151 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.