I have a javascript interface in which I have a browse button to find and attach a file and then upload it to a different directory. Problem is that once I attach a file i don't get full directory path and file not being found during upload. I was able to adjust IE ver.10 settings to show a full path but not in FF ver.21. I understand this is a security issue that should be in place. How would I retrieve a full path using javascript in IE and FF. Sample code would be really helpful. Thanks in advance.
Asked
Active
Viewed 1,269 times
1 Answers
2
You do not need full file path from the client browser since it will have nothing to do with the uploaded destination on the server. Many browsers restrict full local path availability due to security concerns. IE will show full path if you add site to "Trusted Sites", but again there is no need for that.

Yuriy Galanter
- 38,833
- 15
- 69
- 136
-
this may help you http://stackoverflow.com/questions/5628011/how-to-upload-a-file-to-my-server-using-html and http://www.w3schools.com/php/php_file_upload.asp – Swapneel Kondgule Jun 07 '13 at 16:11
-
I understand, but I need a full path for file to be found during upload. I don't need to show it on the application but need to get it in javascript code. – JS11 Jun 07 '13 at 16:13
-
Full path is probably in some hidden field where i can retrieve it from. – JS11 Jun 07 '13 at 16:15
-
If your code could see it - everybody could see it. But again FileUpload control does need full path since browser sends the actual physical file as a part of Response, you just need to read it with server-side code and act accordingly. And no, there is no hidden field, it is not stored anywhere at all. Browser just loads file and doesn't care about the path – Yuriy Galanter Jun 07 '13 at 16:15
-
@JS11: No. The whole point of a security feature is to _prevent_ you from getting that; not to make it slightly harder. – SLaks Jun 07 '13 at 16:33
-
If full path is part of the response send by the browser then how do I get it in the servlet. I get an error file not found unless i am including full path. Forgive me if it is a silly question I am a new to programming. – JS11 Jun 07 '13 at 16:38
-
I am uploading this file using jcraft.jsch and it will throw an exception file not found unless full path of the file is included, so how do i get it from the browser response? – JS11 Jun 07 '13 at 16:59
-
Where are you uploading to? Which server? What code is running on the server-side to accept and save the uploaded file? – Yuriy Galanter Jun 07 '13 at 17:15
-
I am uploading file from jsp page via post to the java servlet that sends it further to java class for uploading to a Unix directory. File uploads fine if I include full local directory path with the file name. Can i get full file path from servlet response? Not sure how to proceed here. – JS11 Jun 07 '13 at 17:27
-
File f = new File(fileFromPath); channelSftp.put(new FileInputStream(f), f.getName()); – JS11 Jun 07 '13 at 17:28
-
2@JS11 If you need the full path of a file uploaded from the client in order to handle the file server-side, your code is flawed and you need to re-think your design. – Ray Nicholus Jun 07 '13 at 18:50
-
You are likely correct, but not that's not really helping me with my problem. At this point I just want to know if there is a way that i can capture file path in the servlet and if I can how? Anybody? – JS11 Jun 07 '13 at 20:11
-
The long answer - only in IE browser if the site is added to "Trusted Sites" list. The short answer - no. – Yuriy Galanter Jun 07 '13 at 20:16
-
@JS11 This reminds me of the famous Henny Youngman one-liner. Patient: "Doctor, it hurts when I do this". Doctor: "Then don't do that". – Ray Nicholus Jun 07 '13 at 20:28
-
Yeah, I actually set security settings to enable to include local directory path when uploading files to a server. Guess it's the same thing. Thank you for your answers, I'll need to rethink my code then. – JS11 Jun 07 '13 at 20:29