Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi,
how to get full file path from input type file?
Posted
Updated 6-Dec-20 4:40am
Comments
Rockstar_ 5-Jun-13 5:44am    
Input type file? Plz describe?
vaibhav10Dec1987 5-Jun-13 5:49am    
<input id="txtFile" type="file"/>
In these while adding a file via browse button. how to get a full path of that file name.

You can't: It's a security feature in all modern browsers.

For IE8, it's off by default, but can be reactivated using a security setting:

C#
When a file is selected by using the input type=file object, the value of the value property depends on the value of the "Include local directory path when uploading files to a server" security setting for the security zone used to display the Web page containing the input object.

The fully qualified filename of the selected file is returned only when this setting is enabled. When the setting is disabled, Internet Explorer 8 replaces the local drive and directory path with the string C:\fakepath\ in order to prevent inappropriate information disclosure.


In all other current mainstream browsers I know of, it is also turned off. The file name is the best you can get.
 
Share this answer
 
Comments
Prasad Khandekar 5-Jun-13 6:20am    
Very good explanation. +5.
Hello,

Here is a small sample demonstrating this. Hope this is what you are looking.
HTML
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function showFileName() {
   var fil = document.getElementById("myFile");
   alert(fil.value);
}
</script>
</head>
<body>
<form id="frmMain" name="frmMain">
    <input type="file" id="myFile" name="myFile"/>
    <a href="#" onclick="showFileName()">Show Name</a>
</form>
</body>
</html>

NoteFor security reasons most of the browser's will only return the file name and not the full path and file name. IE6 and below browsers will return you the desired value

Regards,
 
Share this answer
 
v2
Comments
vaibhav10Dec1987 5-Jun-13 5:56am    
Thanks for your help.
In that case i got only "file Name".But in my scenario I want to get a "full file path
with file name".
Prasad Khandekar 5-Jun-13 6:17am    
For security reasons most of the browser's will only return the file name IE-8 however will return a fake path. IE 6 and below browsers will actually return you the desired value.

Regards,
Member 11035041 18-Sep-14 13:50pm    
I want to share some data of a file from jsp to java so I need the exact path of a file...
Somebody will try and posted here as soon as possible
Prasad Khandekar 1-Oct-14 12:07pm    
Can you please elaborate your requirement? What exactly is the use of knowing file's complete path on the user's computer?
Member 11146598 4-May-16 0:44am    
Hi, Thanks for this.

Can I get the path in other browsers than IE.

I mean can your solution work in another browser(Google Chrome) with any settings.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900