Click here to Skip to main content
14,331,836 members
Rate this:
Please Sign up or sign in to vote.
Hi,
how to get full file path from input type file?
Posted
Updated 7-Aug-19 10:22am
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.
Rate this:
Please Sign up or sign in to vote.

Solution 2

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:

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.
   
Comments
Prasad Khandekar 5-Jun-13 6:20am
   
Very good explanation. +5.
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hello,

Here is a small sample demonstrating this. Hope this is what you are looking.
<!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,
   
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100