homepage Welcome to WebmasterWorld Guest from 54.198.42.105
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP Browse Button
andrewsmd




msg:3699883
 2:55 pm on Jul 16, 2008 (gmt 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,

 

IanKelley




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

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




msg:3700193
 8:29 pm on Jul 16, 2008 (gmt 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,

IanKelley




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

Javascript is an option

andrewsmd




msg:3700367
 12:14 am on Jul 17, 2008 (gmt 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,

eelixduppy




msg:3700474
 4:01 am on Jul 17, 2008 (gmt 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.

eelixduppy




msg:3700480
 4:16 am on Jul 17, 2008 (gmt 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

andrewsmd




msg:3700727
 12:32 pm on Jul 17, 2008 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved