Re: Directory to array to select box...
| From: | Michael Virnstein | Date: | Fri, 05 Apr 2002 16:43:59 +0000 |
| Subject: | Re: Directory to array to select box... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-91742@lists.php.net to get a copy of this message | ||
ok, i'll try to help, but first use "while (false !== ($file =
readdir($dir))". ;)
why do you need hidden fields on that page? to determine which file
the user has selected? hmmm...ok, let's see:
The user sees your form, selects the desired file and submits the form.
Now the page processing the request will know which one was selected.
in your case $files will contain the value of the selected option field
within
the select-box files. So why do you need additional input fields for that?
Please explain a bit more detailed what exactly is your problem.
"Jas" <jlgerfen@hotmail.com> schrieb im Newsbeitrag
news:20020405160407.80092.qmail@pb1.pair.com...
> Ok I tried a different way to do it and this is the resulting code... I
> still need to be able to make some hidden fields so the contents of the
item
> selected may be passed to another script which will stick the path of the
> file into a database table if anyone wants to give me a hand with that
part.
> Here is what I have and it is working as far as just reading the directory
> and putting the contents into a select box...
> <?php
> // varible to hold path to directory we wish to open
> $dir_name = "/path/to/directory/on/server/";
> // opening directory
> $dir = opendir($dir_name);
> // varible to start form
> $file_list .= "<p><FORM METHOD=\"post\"
> ACTION=\"db.php3\">
> <SELECT NAME=\"files\">$file_name";
> // read the directory and place them into file names for further
processing
> while ($file_name = readdir($dir)) {
> // exclude "." and ".." file names
> if (($file_name != ".") && ($file_name !="..")) {
> // variable to place results of directory into select box
> $file_list .= "<OPTION
> VALUE=\"$file_name\">$file_name</OPTION>";
> }
> }
> // closing select and form and adding select button
> $file_list .= "</SELECT><br><br><INPUT TYPE=\"submit\"
> NAME=\"submit\"
> VALUE=\"select\"></FORM></p>";
> // close the directory
> closedir($dir);
> ?>
> If anyone knows how to do this in a better way please let me know, but
this
> works and all it needs is some hidden fields (i am assuming here) so that
> the item that the user selects from the list can be further processed,
like
> sticking the file path (not the actual file) into a database table. (I
need
> help with that...) Enj0y!
> Jas
>
>