nyyankeefan95 Posted November 10, 2010 Share Posted November 10, 2010 Hello i am new to php and i was wondering if someone knew how to do this. I just need a simple index.php file that lists the files and folders in a directory but i need it to look exactly like this (With Bullets): Thank You In Advance (I also need it to open the folder directory if a folder is clicked on and button for Parent Directory) Quote Link to comment https://forums.phpfreaks.com/topic/218250-php-directory-index/ Share on other sites More sharing options...
trq Posted November 10, 2010 Share Posted November 10, 2010 That is done by simply allowing 'directory browsing' within your server configuration. Nothing at all to do with regular expressions or PHP for that matter. Quote Link to comment https://forums.phpfreaks.com/topic/218250-php-directory-index/#findComment-1132478 Share on other sites More sharing options...
nyyankeefan95 Posted November 10, 2010 Author Share Posted November 10, 2010 Yeah but i use godaddy and they dont provide you with indexing so i wanted to do this and i liked the bullet format so if someone can help that would be great. Quote Link to comment https://forums.phpfreaks.com/topic/218250-php-directory-index/#findComment-1132484 Share on other sites More sharing options...
stephenworks Posted November 11, 2010 Share Posted November 11, 2010 Using the readdir() function you should be able to loop through a directory (the current directory) and list out files. You can test if it's a file by using an is_file() test. Try it out. Here's a quick example (untested): <?php if($files = readdir('.')) { while(($file = readdir($handle)) !== false) { echo "<a href='" . $file . "'>" . $file . "</a>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/218250-php-directory-index/#findComment-1132858 Share on other sites More sharing options...
nyyankeefan95 Posted November 11, 2010 Author Share Posted November 11, 2010 I have this code which i want to keep: <?php if ($handle = opendir('.')) { echo "<ul>"; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "<li>$file</li>"; } } echo "</ul>"; closedir($handle); } ?> but i want to add "Index of/" at the top of the page and i want the text to be able to be clicked on to open the file/folder? Quote Link to comment https://forums.phpfreaks.com/topic/218250-php-directory-index/#findComment-1132867 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.