0

I have file upload html code as:

<input type="text" id="txtSelectedFile" value="Select a file" class="sloInputBox" />
                        <input type="file"  id="fUploadArtifact" style="background-color: #249FDA; color: white; height: 22px; width: 45px;border-radius: 4px;" />

And Jquery to get its path as:

$(function()
    {
        $('#fUploadArtifact').on('change',function ()
        {

            $('#txtSelectedFile').val($(this).val());
        });
    });

But each time although i take any file from any of the drive it gives me wrong path as:

C:\fakepath\Readme.txt

I have selected file from E:\Observations\Readme.txt

But it given me C:\fakepath\Readme.txt

What can be the mistake?

Please help me.

C Sharper
  • 8,284
  • 26
  • 88
  • 151

3 Answers3

2

Due to security reasons it is not possible to get actual file path when using html file type.

Nikhil Talreja
  • 2,754
  • 1
  • 14
  • 20
1

Its a security feature to prevent JavaScript from knowing your file's local path

iJade
  • 23,144
  • 56
  • 154
  • 243
1

Almost all browsers have a security feature that prevents javascript from knowing your file's local full path. It makes sense - as a client, you don't want the server to know your local machine's filesystem. It would be nice if all browsers did this.

You may get good explanation here

Community
  • 1
  • 1
Pratik Joshi
  • 11,485
  • 7
  • 41
  • 73