Jump to content

Drop down menu and php?


Wideawake

Recommended Posts

So Im working on making a very simple php script to pull filenames from a directory and post the link as the same of the file. I a b00n when it comes to php and Im trying to learn. So far I got this piecing together some stuff. If anyone could help make it all in one drop down and remove the . and .. boxes it would be great!

Thanks for any help in advanced,

Mike

 

<?php

$dir="/my/file/downloads"; // Directory where files are stored

if ($dir_list = opendir($dir))
{
while(($filename = readdir($dir_list)) !== false)
{
echo '<SELECT name=ID>';
echo '<OPTION value='.$filename.'> '.$filename.'';
echo '</select>'; 

?>

<?php
}
closedir($dir_list);
}
?>

<input type="submit" value="Download" name="Download">

Link to comment
https://forums.phpfreaks.com/topic/110274-drop-down-menu-and-php/
Share on other sites

<?php
$dir="/my/file/downloads"; // Directory where files are stored

if ($dir_list = opendir($dir))
{
echo '<SELECT name=ID>';
while(($filename = readdir($dir_list)) !== false)
{
if($filename != '..' && $filename != '.'){
echo '<OPTION value='.$filename.'> '.$filename.'</option>';
}
}
echo '</select>';
closedir($dir_list);
}
?>

<input type="submit" value="Download" name="Download">

 

that should work better

Very nice! Thanks so much for your help! You wouldn't happen to know if theres a way to put txt in the first then drop down and see files? Like when you get to the page it says Choose File to Download, then drop down with all the files in it? Again I do appreciate your time helping the b00n. :D

~Mike

Of course there are ways of doing these things. Were not here to pump out code for you though, how about your start by trying to write something and post your code when you run into trouble.

 

Thats what I did at first :P but I know this has got to be a one liner.....lol at least I admit Im a b00n and I have searched, so its not like Im not trying. ;)

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.