php_joe Posted May 20, 2006 Share Posted May 20, 2006 I modified the code provided by [b]shocker-z[/b] in [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=89695&st=0&p=375454entry375454\" target=\"_blank\"]directory listing problem[/a] for listing the contents of a directory so that it wouldn't show the file extensions.[code]$path = "./";$dir = opendir($path);echo "<ul>\n";while($file = readdir($dir)){if ($file != "." && $file != ".." && $file != ".php"){list ($name, $ext) = explode (".", $file); echo "<li><a href = \"" .$path.$file. "\" target = \" _blank\"> ".$name." </a></li> \n";}}echo "</ul>\n";closedir($dir);[/code]Anyone know how to make it show only folders, or to specific file types?Joe Link to comment https://forums.phpfreaks.com/topic/10069-removing-extensions-from-directory-listings/ Share on other sites More sharing options...
yonta Posted May 20, 2006 Share Posted May 20, 2006 You could use the [a href=\"http://pt.php.net/manual/en/function.pathinfo.php\" target=\"_blank\"]pathinfo [/a]function.From the manual:[code]<?php$path_parts = pathinfo('/www/htdocs/index.html');echo $path_parts['dirname'], "\n";echo $path_parts['basename'], "\n";echo $path_parts['extension'], "\n";?>[/code]Would produce:/www/htdocsindex.htmlhtml Link to comment https://forums.phpfreaks.com/topic/10069-removing-extensions-from-directory-listings/#findComment-37456 Share on other sites More sharing options...
php_joe Posted May 21, 2006 Author Share Posted May 21, 2006 [!--quoteo(post=375531:date=May 21 2006, 12:37 AM:name=yonta)--][div class=\'quotetop\']QUOTE(yonta @ May 21 2006, 12:37 AM) [snapback]375531[/snapback][/div][div class=\'quotemain\'][!--quotec--]You could use the [a href=\"http://pt.php.net/manual/en/function.pathinfo.php\" target=\"_blank\"]pathinfo [/a]function.[/quote]Thanks!Now for what is probably a stupid question...The opendir() function will only open a folder on my website, right? If I have two websites (hosted on different servers) can I list the contents in a folder located on one website on a page located on the other?Joe Link to comment https://forums.phpfreaks.com/topic/10069-removing-extensions-from-directory-listings/#findComment-37694 Share on other sites More sharing options...
haydndup Posted May 21, 2006 Share Posted May 21, 2006 I modified the supplied code, and I could not get it to list the contents in a directory of one of my websites. So, my guess would be that it's not possible. However, I may be wrong. Link to comment https://forums.phpfreaks.com/topic/10069-removing-extensions-from-directory-listings/#findComment-37703 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.