suttercain Posted April 7, 2007 Share Posted April 7, 2007 Hi everyone, I just wrote this code: $dir = "/images/news"; print "<select name='file'>"; $dir = opendir($dir); while (false !== ($file = readdir($dir))){ if (in_array($file, array(".", ".."))) continue; print "<option value='$file'>$file</option>"; } print "</select>"; But for some reason it is not populating. It instead echoes an empty drop down menu. Can anyone suggest anything? Thank you for your help. Link to comment https://forums.phpfreaks.com/topic/46053-solved-populating-a-drop-down-via-a-file-directory/ Share on other sites More sharing options...
Demonic Posted April 7, 2007 Share Posted April 7, 2007 try using glob() http://us3.php.net/glob Link to comment https://forums.phpfreaks.com/topic/46053-solved-populating-a-drop-down-via-a-file-directory/#findComment-223769 Share on other sites More sharing options...
suttercain Posted April 7, 2007 Author Share Posted April 7, 2007 Okay I got it populated via the file directory. I had a slash before images when I shouldn't have. BUT...Now I am having another issue with it. The code is in a form. The user selects the image from the drop down and submits it. One the next page the image they selected is echoed in the browser. PROBLEM:No matter which image they select the same one comes up over and over. Here is the Form Code: <form action="preview_news.php" method="post"> <select name='image'> <?php $dir = "images/news"; $dir = opendir($dir); while (false !== ($image = readdir($dir))){ if (in_array($image, array(".", ".."))) continue; ?> <option value='<?php echo $image; ?>'><?php echo $image; ?></option> <?php } ?> </select> And Here is the page that echos the picture (should be) based on the selection: <?php session_start(); $_SESSION['image'] = $_POST['image']; $image = $_SESSION['image']; echo "<b>IMAGE:</b><br><img src='images/news/" . $row['image'] ."' /><br><br>"; ?> I am at a loss. I got the menu populated... but it's ignoring my selection... Any ideas? Thanks guys! Link to comment https://forums.phpfreaks.com/topic/46053-solved-populating-a-drop-down-via-a-file-directory/#findComment-223804 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.