sayedsohail Posted September 29, 2007 Share Posted September 29, 2007 Hi everyone, function below just display files and folder but no the supplied path ie., http://localhost/xyz/ it just display files and folders where this script is saved not the supplied path. Can someone please have a look at it. Thanks, <?php function showContent($path){ if ($handle = opendir($path)) { $up = substr($path, 0, (strrpos(dirname($path."/."),"/"))); echo "<tr><td colspan='3'>"; echo "<a href='".$_SERVER['PHP_SELF']."?path=$up'>Up one level</a>"; echo "</td></tr>"; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $fName = $file; $file = $path.'/'.$file; if(is_file($file)) { echo "<tr><td> -F- <a href='".$file."'>".$fName."</a></td>" ."<td align='right'>".date ('d-m-Y H:i:s', filemtime($file))."</td>" ."<td align='right'>".filesize($file)." bytes</td></tr>"; } elseif (is_dir($file)) { print "<tr><td colspan='3'> -D- <a href='".$_SERVER['PHP_SELF']."?path=$file'>$fName</a></td></tr>"; } } } closedir($handle); } } ?> <table width="100%" border='1'> <?php $actpath ="http://localhost/"; showContent("$actpath"); ?> </table> Link to comment https://forums.phpfreaks.com/topic/71200-simple-directory-listing-supplied-path-not-showing-anything/ Share on other sites More sharing options...
sayedsohail Posted September 30, 2007 Author Share Posted September 30, 2007 ??? Link to comment https://forums.phpfreaks.com/topic/71200-simple-directory-listing-supplied-path-not-showing-anything/#findComment-358546 Share on other sites More sharing options...
cooldude832 Posted September 30, 2007 Share Posted September 30, 2007 why not try glob instead? Link to comment https://forums.phpfreaks.com/topic/71200-simple-directory-listing-supplied-path-not-showing-anything/#findComment-358553 Share on other sites More sharing options...
sayedsohail Posted October 1, 2007 Author Share Posted October 1, 2007 what is glob? Link to comment https://forums.phpfreaks.com/topic/71200-simple-directory-listing-supplied-path-not-showing-anything/#findComment-359039 Share on other sites More sharing options...
sayedsohail Posted October 1, 2007 Author Share Posted October 1, 2007 i tried glob, but not sure how to make like proper listing in table with filename, filesize etc. the code below just shows the results all in one row <?php $images = glob("../{*.jpg,*.gif,*.png,*.php}", GLOB_BRACE); $dir = '../pdf/'; foreach(glob($dir.'*.*') as $file) { print $file . "\n"; } foreach($images as $file2){ { print $file2 . "\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/71200-simple-directory-listing-supplied-path-not-showing-anything/#findComment-359069 Share on other sites More sharing options...
sayedsohail Posted October 1, 2007 Author Share Posted October 1, 2007 ??? Link to comment https://forums.phpfreaks.com/topic/71200-simple-directory-listing-supplied-path-not-showing-anything/#findComment-359584 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.