[SOLVED] direcotry select

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

[SOLVED] direcotry select

Post 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
Last edited by sharyn on Mon Aug 23, 2004 5:20 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post 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!
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

Post 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
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

Post 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
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post 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);
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post 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);
Last edited by Joe on Mon Aug 09, 2004 4:22 pm, edited 1 time in total.
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

Post 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
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

Post 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...
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post 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. ;)
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

Post 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....
User avatar
sharyn
Forum Commoner
Posts: 33
Joined: Tue Jun 15, 2004 6:39 pm
Location: So Cal

Post 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 !!! :D :D :D

I'd like for it to look like the common dialog control because that's what everyone is used to...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
Post Reply