question about directories

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

Post Reply
glawen
Forum Newbie
Posts: 3
Joined: Tue May 09, 2006 3:34 pm

question about directories

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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
glawen
Forum Newbie
Posts: 3
Joined: Tue May 09, 2006 3:34 pm

Post 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
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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?
User avatar
$phpNut
Forum Commoner
Posts: 40
Joined: Tue May 09, 2006 5:13 pm

Post 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 ...
glawen
Forum Newbie
Posts: 3
Joined: Tue May 09, 2006 3:34 pm

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

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