Welcome to WebmasterWorld Guest from 54.161.108.158

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Browse Button

     
2:55 pm on Jul 16, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 10, 2008
posts: 1130
votes: 0


Does anyone know how to use a Browse for a file button in PHP. Basically what I want to do is have a browse button that you can browse for a file with. I have the browse button code like this. <FORM name = "fileSplit" method = "post">
Insert path: <INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" name = "submit" VALUE="Split File"></FORM>

Now I have read some things about ENCTYPE = multipart/form-data. I don't really need to read the file however I just want to get the path. What I mean is say the file they uploaded was c:\some folder\file.txt on their local machine I would like to get that path. This is just for our intranet so these paths I can pass in directly to work with the file. Also, would there be any way to get the full path if they enter a mapped drive. What I mean is say a machine is named machine01. Now on their machine that drive may be X:\some folder and on my machine that drive may be mapped as M:\some folder. I would like to get that as \\machine01\some folder. Any help on how to do this, I'm rather lost so any suggestions would be great. Thanks,

7:41 pm on July 16, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 4, 2001
posts: 1265
votes: 13


I would be willing to bet that a browser will not pass that data under any circumstances. It's a security risk.

You would need to run an activeX control or some other form of client side software.

Either that or have the user input the file path themselves.

8:29 pm on July 16, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 10, 2008
posts:1130
votes: 0


I have another text box that allows them to input it manually and the user can copy and paste the path that the browse button fills in the text box, I just wanted to make it so the user would not have to copy and paste. If there is no way around it that is ok. Thanks,
10:09 pm on July 16, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Oct 4, 2001
posts: 1265
votes: 13


Javascript is an option
12:14 am on July 17, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 10, 2008
posts:1130
votes: 0


Yes I know, I just didn't want to have to mess with JS because I hate it and it is not powerful enough to do what I want. I would end up with a mess of PHP and JS or setting a header in PHP to output in JS and I don't want to deal with that headache. Thanks,
4:01 am on July 17, 2008 (gmt 0)

Senior Member

joined:Nov 12, 2005
posts:5967
votes: 0


>> it is not powerful enough

I disagree. For what you need (to send the path using POST) this is definitely 'powerful' enough, and might even be one of your only solutions.

>> I would end up with a mess of PHP and JS

If you properly organize your code this shouldn't be an issue at all.

4:16 am on July 17, 2008 (gmt 0)

Senior Member

joined:Nov 12, 2005
posts:5967
votes: 0


Alright ran a quick test. Calling the value of the file element in a form gives you the path of the file. This only works in Internet Explorer, however; I tested it on Opera and Firefox, as well, and you only get the filename not the whole path. In any case, since this is for your intranet, I don't think it would be too much to ask if they used IE to use it, although there might be a more universal solution, I just don't know of it. But to get the filename in IE, it looks something like this:

var file_path = document.getElementById("browse").value
12:32 pm on July 17, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:June 10, 2008
posts:1130
votes: 0


Yea I may break down and use JS but try to figure out a way to get it to work. As far as the IE thing goes, everyone in the office uses IE. I'm the only person who uses FF (because it is simply much more user friendly). Usually, I have the problem of things working or looking fine in FF and Opera, but not working or showing correctly in IE so this will be a first. Thanks for all of your help.