Warptweet Posted January 14, 2007 Share Posted January 14, 2007 Here is my code for directory listing...[code]<?//define the path as relative$path = "211612151419/";//using the opendir function$dir_handle = @opendir($path) or die("Unable to view Flash Portal in $path");echo "Flash Portal $path<br/>";//running the while loopwhile ($file = readdir($dir_handle)) { if($file!="." && $file!="..") echo "<a href='$file'>$file</a><br/>";}//closing the directoryclosedir($dir_handle);?> [/code]How can I do the following...-ONLY list .php files-Do NOT display the .php extension, only the name before the .phpThanks, I'd really appreciate any help! Quote Link to comment https://forums.phpfreaks.com/topic/34172-directory-list-code-need-help/ Share on other sites More sharing options...
Warptweet Posted January 14, 2007 Author Share Posted January 14, 2007 By the way...IF IT IS POSSIBLEand IF you know how...Would you mind seeing if you can show me...-20 newest .php files createdThat way I can see the files that were just created... Quote Link to comment https://forums.phpfreaks.com/topic/34172-directory-list-code-need-help/#findComment-160805 Share on other sites More sharing options...
Philip Posted January 15, 2007 Share Posted January 15, 2007 I think this is one correct way of doing it. [code]<?php//define the path as relative$path = "211612151419/";//using the opendir function$dir_handle = @opendir($path) or die("Unable to view Flash Portal in $path");echo "Flash Portal $path<br/>";$count = 0;//running the while loopwhile ($file = readdir($dir_handle)) { if($count == 20) { break;} // If 20 results, stop loop if($file!="." && $file!="..") $ext = substr($file, strrpos($file, '.') + 1); // get extension if($ext == "php") { // if .php echo "<a href='$file'>$file</a><br/>"; // echo link } $count++;}//closing the directoryclosedir($dir_handle);?> [/code]I could be completely wrong, and if I am, Sorry! :( Quote Link to comment https://forums.phpfreaks.com/topic/34172-directory-list-code-need-help/#findComment-160824 Share on other sites More sharing options...
Barand Posted January 15, 2007 Share Posted January 15, 2007 try[code]<?php$dir = 'c:/inetpub/wwwroot/test/';$H = opendir($dir);while (($file = readdir($H))!==false) { if ($file != '.' && $file != '..') { $a = explode('.', $file); if ($a[1]=='php') { $d = filemtime("$dir$file"); $res[$a[0]] = $d; } }}closedir($H);// sort by date descarsort($res);// list 20 only$res = array_slice($res, 0, 20);foreach ($res as $f => $d) echo "$f<br>"; ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34172-directory-list-code-need-help/#findComment-160826 Share on other sites More sharing options...
Warptweet Posted January 19, 2007 Author Share Posted January 19, 2007 Sorry, I have a new code...[code]<?php$dir = 'c:/inetpub/wwwroot/test/';$H = opendir($dir);while (($file = readdir($H))!==false) { if ($file != '.' && $file != '..') { $a = explode('.', $file); if ($a[1]=='php') { $d = filemtime("$dir$file"); $res[$a[0]] = $d; } }}closedir($H);// sort by date descarsort($res);// list 20 only$res = array_slice($res, 0, 20);foreach ($res as $f => $d) echo "$f<br>"; ?>[/code]Theres only one problem now.They wont show up as links!How can I make the displayed directory files show as links? Quote Link to comment https://forums.phpfreaks.com/topic/34172-directory-list-code-need-help/#findComment-164155 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.