IamTomCat Posted January 23, 2015 Share Posted January 23, 2015 Hi , I am pretty new to php. I would like to create a php website based on folders. I have a code so far that shows the names of folder in a selection box. What I would like to achieve now is how i get the images inside the folder after I click on submit. I know how to get the images with a glob function. What I don't know is how to get the value of each specific folder name. How would I do that? I have this code so far to get the names of the folders in the selection box: <form action="test.php" method="post"> <select name="myDirs"> <option value="" selected="selected">Select a genre</option> <?php $dirs = glob("*", GLOB_ONLYDIR); foreach($dirs as $val){ echo '<option value="'.$val.'">'.$val."</option>\n"; } ?> </select> <input type="submit" name="submit2"> <?php if (isset($_POST['submit2'])) foreach($dirs as $val){ { echo $val; } } ?> </form> How could get I'm now images which are in the folder of which folder names appear in the selection box? Quote Link to comment https://forums.phpfreaks.com/topic/294183-get-value-from-drop-down-list/ Share on other sites More sharing options...
CroNiX Posted January 23, 2015 Share Posted January 23, 2015 //basically the same way you got the dir names...with glob() $selected_dir = $_POST['myDirs']; //you called it 'myDirs' in the form. $images = glob($selected_dir . '*'); Quote Link to comment https://forums.phpfreaks.com/topic/294183-get-value-from-drop-down-list/#findComment-1503955 Share on other sites More sharing options...
Monkuar Posted January 23, 2015 Share Posted January 23, 2015 (edited) This needs to be moved. Wrong forum section bud Edited January 23, 2015 by Monkuar Quote Link to comment https://forums.phpfreaks.com/topic/294183-get-value-from-drop-down-list/#findComment-1503962 Share on other sites More sharing options...
CroNiX Posted January 23, 2015 Share Posted January 23, 2015 Moved to PHP Coding Help... Quote Link to comment https://forums.phpfreaks.com/topic/294183-get-value-from-drop-down-list/#findComment-1503963 Share on other sites More sharing options...
IamTomCat Posted January 23, 2015 Author Share Posted January 23, 2015 Hi. Many thanks for the reply. Unfortunat it didn't work. My main issues how I access the value of each folder. And then for each folder to access the images. Let's say I select the folder name "Toy story". Then I want all the images that are in the folder Toy Story. When I select the let's say the folder name "Brain", then I want every image that is in the folder "Brain". Help would be very much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/294183-get-value-from-drop-down-list/#findComment-1503971 Share on other sites More sharing options...
Barand Posted January 23, 2015 Share Posted January 23, 2015 Unfortunat it didn't work. Then you did it wrong, but, without your posting the code you now have, we cannot say what you did wrong Quote Link to comment https://forums.phpfreaks.com/topic/294183-get-value-from-drop-down-list/#findComment-1503977 Share on other sites More sharing options...
CroNiX Posted January 23, 2015 Share Posted January 23, 2015 (edited) I just tested it and this worked fine. You'd just need to define the $source_dir at the top. <?php $source_dir = '/home/users/images/'; ?> <form action="test.php" method="post"> <select name="myDirs"> <option value="" selected="selected">Select a genre</option> <?php foreach(glob($source_dir . "*", GLOB_ONLYDIR) as $val){ echo '<option value="'.$val.'">'.$val."</option>\n"; } ?> </select> <input type="submit" name="submit2"> </form> <?php if (isset($_POST['submit2'])) { //get the dir from POST $selected_dir = $_POST['myDirs']; //now get the files from within the selected dir and echo them to the screen foreach(glob($selected_dir . DIRECTORY_SEPARATOR . '*') as $filename) { echo "$filename<br>"; } } ?> Edited January 23, 2015 by CroNiX Quote Link to comment https://forums.phpfreaks.com/topic/294183-get-value-from-drop-down-list/#findComment-1503981 Share on other sites More sharing options...
IamTomCat Posted January 23, 2015 Author Share Posted January 23, 2015 Worked brilliant Thanks Quote Link to comment https://forums.phpfreaks.com/topic/294183-get-value-from-drop-down-list/#findComment-1503998 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.