Jump to content

[SOLVED] Populating a Drop Down via a file directory?


suttercain

Recommended Posts

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.

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!

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.