[SOLVED] direcotry select
Moderator: General Moderators
[SOLVED] direcotry select
I've been looking in different forums for this question and I haven't found it yet (unless I'm not typing in the right thing)... I'm trying to choose a directory to search. It sounds so simple, but I can't figure it out.
I'd like to be able to choose a directory to recurse through and list the files. I've got code to do that and it works just fine, but in order to choose a directory I am using the html <input type="file"...> command then hacking off the file name. Well that's not to handy and it's ugly as well, but how else can I do with a browse type look that everyone is used to?
Thanks,
sharyn
I'd like to be able to choose a directory to recurse through and list the files. I've got code to do that and it works just fine, but in order to choose a directory I am using the html <input type="file"...> command then hacking off the file name. Well that's not to handy and it's ugly as well, but how else can I do with a browse type look that everyone is used to?
Thanks,
sharyn
Last edited by sharyn on Mon Aug 23, 2004 5:20 pm, edited 1 time in total.
POST from the input field on the previous form!
Code: Select all
if ($open = opendir($_POST['directory']))
{
while(false != ($file = readdir($open)))
{
echo "$file<br>";
}
closedir($open);You could use a drop down menu which holds the files/directorys for you to choose.sharyn wrote:Joe, I'm trying not to type it in by hand. I want it to work like the html <input type="file"..> tag, but not have to choose a file. I want to choose the directory.
- sharyn
Untested:
Code: Select all
echo "<select name='files'>";
if ($open = opendir('dirname'))
{
while(false != ($file = readdir($open)))
{
echo "<option value='$file'>$file</option>";
}
echo "</select>";
closedir($open);
Last edited by Joe on Mon Aug 09, 2004 4:22 pm, edited 1 time in total.
Joe, that's what I'm doing now :
but instead of <input type="file"> where I have to choose a file or <input type="text"> where I have to type it in, I want to be able to browse for the directory.
- sharyn
Code: Select all
<form action="directory.php" method="get" name="DirList">
<input name="dirpath" type="file" size="50">
<input name="Select" type="submit" value="Dir">
</form>- sharyn
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
the server doesn't have access to your local directories unless it's running on your machine.. when you open explorer, it starts the view from some location. You need to have some way of determining a default location to start your directory traversal from. One thing you can do, is remember where the last were..
If that was aimed at me then you misunderstood what I said. I think the user is asking to browse remotly with the input tag holding "file" attributes. When you use this tag it displays the files on your machine. Think of the common dialog control.the server doesn't have access to your local directories unless it's running on your machine
Joe,
I'd like for it to look like the common dialog control because that's what everyone is used to...
Bingo !!!Joe wrote:I think the user is asking to browse remotly with the input tag holding "file" attributes. When you use this tag it displays the files on your machine. Think of the common dialog control.
I'd like for it to look like the common dialog control because that's what everyone is used to...
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
okay.. that's what I figured.. yet the form input for files, will look on your local machine, not on the server.. you need to tell the script to default from somewhere on the server.. there's no getting around that. As I suggested, you can save the last location you were in "searching" through.. of course, you have to protect against the CD drive, since it may be empty the next time around..