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
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.