thisperishedmin Posted May 17, 2007 Share Posted May 17, 2007 hello everyone, im pretty new to PHP and still trying to grasp the power in this language (and web development as a whole). as part of an assignment i was given, I need to create an image gallery with navigation based on dropdown menus. The idea was explained to me based on the postback feature of asp.net - where you could make a selection in the first menu (dynamically generate based off of the file system), and it would dynamically generate the submenu and display any images. Now i realize PHP is a completely different animal and that this task is utterly horrid for a learner, but theres not much I can do but try to devise some kind of method to do the same thing. I was wondering if anyone has any kind of helpful input or code examples to do this? My largest problems are that while I can create a while loop to continue to generate the menus, i lack anyway to hold the "selection" that was made and accurately maintain the current directory path.... Additionally, I am having trouble with the is_dir and is_file functions to identify the contents of a selected directory to ultimately detect whether or not it should create another dropdown and/or display the thumbnails of images. Hopefully some of this makes sense, im open to any suggestions and questions to try and work through this. id love to create a set of functions for others to use to create the dynamically generated series of dropdown navigation menus and make it available to everyone. In either case, thanks in advance! EDIT: I am working off the local host if it has any effect.... heres the extremely rough code with lots of random output to try and track whats going on. its a mess ...thanks again... <?php function listgen($directory) { echo "<form method = 'POST'> <div align='left'> <select name = 'dropdown'>"; $dropdown = array(); if ($handle = opendir($directory)); while ( false !== ($folders = readdir($handle)) ) { if ($folders == "." || $folders == "..") { continue; } array_push ($dropdown, $folders); } foreach($dropdown as $item) { echo "<option value='" . $item . "'>" . $item . "</option>"; } echo "</select> <input type = 'submit' value = 'Go'>"; } $filepath = 'images/'; listgen ("$filepath"); if ( isset($_POST['dropdown'])) { $filepath = $filepath .= $_POST['dropdown'] .= '/'; echo $filepath . "<p>"; //function to check for folders if (is_dir($filepath)) { if ($handle = opendir($filepath)) { while (($path = readdir($handle)) !== false) { //test if a folder if (is_dir($path)) { echo "</br> Folder exists"; $folder_exists = '1'; break; } } } } //function to check for images if (is_dir($filepath)) { if ($handle = opendir($filepath)) { while (($path = readdir($handle)) !== false) { //test if a file if (is_file($path)) { echo "</br> file exists"; $file_exists = '1'; break; } } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51775-dropdown-menus-and-postback-with-php/ Share on other sites More sharing options...
neel_basu Posted May 17, 2007 Share Posted May 17, 2007 Nobody needs to know the story to solve a problem. Ask questions / Solutions if you have problem and explain your problem not your story else nobody can help you. Quote Link to comment https://forums.phpfreaks.com/topic/51775-dropdown-menus-and-postback-with-php/#findComment-255080 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.