Page 1 of 2
[SOLVED] direcotry select
Posted: Mon Aug 09, 2004 4:12 pm
by sharyn
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
Posted: Mon Aug 09, 2004 4:14 pm
by feyd
display a list of directories and files in the starting folder... and run through them with your function.. I'm not sure I fully understand..
Posted: Mon Aug 09, 2004 4:15 pm
by Joe
Well you could just use an input field and type in the file name. Perhaps you should also use glob() to search particular filename patterns!
Posted: Mon Aug 09, 2004 4:17 pm
by sharyn
I am displaying a list of directories & their files. I have working code for this, but I have to hard code the directory in or type it in by hand in an input box. I'd like some way of browsing for it like you can a file.
- sharyn
Posted: Mon Aug 09, 2004 4:18 pm
by sharyn
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
Posted: Mon Aug 09, 2004 4:19 pm
by Joe
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);
Posted: Mon Aug 09, 2004 4:20 pm
by Joe
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
You could use a drop down menu which holds the files/directorys for you to choose.
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);
Posted: Mon Aug 09, 2004 4:21 pm
by sharyn
Joe, that's what I'm doing now :
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>
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
Posted: Mon Aug 09, 2004 4:23 pm
by sharyn
Joe,
I don't know all the directory locations that the data will be sitting in...That's why I want them to tell me...
Posted: Mon Aug 09, 2004 4:24 pm
by Joe
I don't think you can use the file attribute in input tags to view files remotly, only locally fom what I know! You can try the code I just posted above for drop down!
Posted: Mon Aug 09, 2004 4:24 pm
by feyd
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..
Posted: Mon Aug 09, 2004 4:28 pm
by Joe
the server doesn't have access to your local directories unless it's running on your machine
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.

Posted: Mon Aug 09, 2004 4:28 pm
by sharyn
Feyd,
The files will have been uploaded to the server from someone else or someone will put a cd in, so it will be looking on the server for the files....
Posted: Mon Aug 09, 2004 4:30 pm
by sharyn
Joe,
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.

Bingo !!!
I'd like for it to look like the common dialog control because that's what everyone is used to...
Posted: Mon Aug 09, 2004 4:34 pm
by feyd
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..