Nic727 Posted August 31, 2016 Share Posted August 31, 2016 Hi, For the moment I have this as directory : - Animal - People --- Number1.html --- Number2.html - test.php That's just an example, but I would like to get a form showing options to select a folder in the current location. Here is my code for now : <select name='choice'> <option value="" disabled selected hidden>Folders</option> <?php $folder = getcwd(); echo $folder; $element = scandir($folder); foreach($element as $file){ if($file != '.' && $file!= '..'){ echo "<option>".$file."</option><br/>";}} ?> </select> For now it show all files/folders in my current location in directory. So it show my test.php in the list. I would like to only get folders and when I select a folder and click the submit button, it should show another select options with the files inside the chosen folder. After when you click the submit button again with the selected file, it should open this file in the browser. Thank you. Link to comment Share on other sites More sharing options...
dsonesuk Posted August 31, 2016 Share Posted August 31, 2016 Use is_dir() to test if directory before listing in options. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 31, 2016 Share Posted August 31, 2016 The SPL also has some classes that provide wrappers for the various filesystem functions: http://php.net/manual/en/class.directoryiterator.php http://php.net/manual/en/class.splfileinfo.php Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now