Page 1 of 1

question about directories

Posted: Tue May 09, 2006 3:41 pm
by glawen
Hi,

Is it possible to make a html form which prompts for a directory (and not for a file) ?

If it's not, how do I get, in a php script, the path of a file whose name I've transmitted with an ' input type="file" ' tag ?

(I want to make a script which lists all the files in a user chosen directory)

TIA

Posted: Tue May 09, 2006 3:50 pm
by Oren
:?: :?: :?:

Not sure what you are talking about but you might want to check one of these:
http://us2.php.net/manual/nl/function.scandir.php
http://us2.php.net/manual/nl/function.glob.php

Posted: Tue May 09, 2006 4:05 pm
by glawen
Thanks for your answer,

but I don't want to write the path in my script (something like $path = 'tmp/dir')
I would like the user to choose a path (maybe only possible by choosing a file in that path) in a HTML form, and I would like to know the php function wich gives me the path the user chose (or the path of the file he chose).

So, I was planning to make a form with an 'input type = "file"' tag, so the user would have to chose a file.
Then I would like my php script to give back the path of the file he chose (if he chose the file "c:\text\document.txt", I would like to know how to get "c:\text\" in a variable)

TIA

Posted: Tue May 09, 2006 4:12 pm
by Oren
I don't know any function that does that, I don't think it is even possible but who knows I might be wrong.
I guess it is possible with JavaScript though.
If it is possible with PHP, does anybody know how?

Posted: Tue May 09, 2006 5:21 pm
by $phpNut
I've never tried this before, but when you enter the php script try using

$_POST['file_form_item']

in theory it should return the value in the text box, then use pathinfo() ... but even then your still uploading the file before hand ...

Posted: Tue May 09, 2006 7:03 pm
by glawen
Thank you both for your answers,

I cannot use $_POST['file_form_item'], beacause it only returns the filename and not the path.
So, I cannot use pathinfo() either, because it needs a complete path (in a string variable).

If anyone knows a workaround, please let me know.


TIA

Posted: Tue May 09, 2006 7:07 pm
by RobertGonzalez
You might need to use some javascript that takes whatever is in the filename form field and copies it to a hidden text field. Then, when the form is posted, upload the file from the filename field but use the text in the text box field for the path. This is not a best way to do it, but it should give you what you want.