Welcome to WebmasterWorld Guest from 54.226.67.166

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Browse Button

     

andrewsmd

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

WebmasterWorld Senior Member 5+ Year Member



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,

IanKelley

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

WebmasterWorld Senior Member 10+ Year Member



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.

andrewsmd

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

WebmasterWorld Senior Member 5+ Year Member



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,

IanKelley

10:09 pm on Jul 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Javascript is an option

andrewsmd

12:14 am on Jul 17, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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,

eelixduppy

4:01 am on Jul 17, 2008 (gmt 0)

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



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

eelixduppy

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

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 5+ Year Member



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

andrewsmd

12:32 pm on Jul 17, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month