Forum Moderators: coopster

Message Too Old, No Replies

form SUBMIT takes you to url of <option>

<option> is simply the url of the files in the options

         

AlchemyX

7:39 pm on Sep 26, 2005 (gmt 0)



I wrote a directory indexing script that makes it into a form and options, it simply lists the files in a directory...

but I need to get the form to send people to the files when they click to download.

but for some reason, when I use this... I get an extra "?=" before the file name...

here's my code.

<?php
if ($_POST['submit'])
{
copy($_FILES['file']['tmp_name'], $_FILES['file']['name']);
}
?>
<html>
<head><title>page</title>
</head>
<body>
<?php
$dir=opendir("my_physical_path(s3cr3t)");
$files=array();
while (($file=readdir($dir))!== false)
{
if ($file!= "." and $file!= ".." and $file!= "index.php")
{
array_push($files, $file);
}
}
closedir($dir);
sort($files);
print "<FORM METHOD=GET ACTION=http://www.example.com/music/populargames/>
<SELECT name='$file'>";
foreach ($files as $file)
print "
<OPTION>$file";
print "
</SELECT>
<INPUT TYPE=SUBMIT value=Download>
</FORM>";
?>

</body>
</html>

[edited by: coopster at 11:32 pm (utc) on Sep. 28, 2005]
[edit reason] generalized url per TOS [webmasterworld.com] [/edit]

coopster

11:47 pm on Sep 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld,

I see two things ... I think. First, in your form you are assigning a variable to the <SELECT> name when I think you really just want the name 'file' as that is what you are referring to in your copy() function.

<SELECT name='file'>"; // get the dollar sign out of there

Next you are using the $_FILES superglobal but you aren't uploading any files ... doesn't make sense. I think you want to use the $_POST superglobal there instead, don't you?