6

I face the following problem:

When a user uploads a file with the HTML file input and I then want to receive the file path itself. I only get C:/fakepath/filename.txt for example.

I understand that it is a security reason for browsers to know the exact path of the file. So i was wondering if it is even possible with some hack, some way in .net or with additional jquery/js plugin to get the full path of the file.

Why?

We dont want to upload the file itself to our server filesystem, neither to the database. We just want to store the local path in the database so when the same user opens the site, he can click on that path and his local file system opens.

Any suggestions or recommendations for this approach?

If this is really not possible like

How to resolve the C:\fakepath?

How To Get Real Path Of A File Using Jquery

we would need to come up with a diffrent idea I guess. But since some of the answers are really old, I thought maybe there is a solution to it by now. Thx everyone

8
  • 4
    What's the benefit of a security feature you can hack?
    – Teemu
    Commented May 23, 2018 at 9:22
  • Would you want other websites to be able to do this? Commented May 23, 2018 at 9:22
  • @Teemu I thought maybe reading just exact this path would be possible with a browser. Not having access to the filesystem itself. Because for example IE is showing the real path in the input field. But you can not access it
    – G43beli
    Commented May 23, 2018 at 9:27
  • The security feature here is to hide the pathname ... Use IE with file protocol if you want to get the real path.
    – Teemu
    Commented May 23, 2018 at 9:32
  • 1

3 Answers 3

2

You can't do it.

And if you find a way, it's big security vulnerability that the browser manufacturer will fix when discovered.

0
1

As my goal was to make the uploaded file name visible to the End User and then send it via php mail() function, All I did to resolve this was:

in your js file

Old function:

var fileuploadinit = function(){
    $('#career_resume').change(function(){
        var pathwithfilename = $('#career_resume').val();
        $('.uploadedfile').html("Uploaded File Name :" + pathwithfilename).css({
            'display':'block'
        });
    });
};

Corrected function:

var fileuploadinit = function(){
    $('#career_resume').change(function(){
        var pathwithfilename = $('#career_resume').val();
        var filename = pathwithfilename.substring(12);
        $('.uploadedfile').html("Uploaded File Name :" + filename).css({
            'display':'block'
        });
    });
};
$(document).ready(function () {
fileuploadinit();
});

Old result:

Uploaded File Name :C:\fakepath\Coverpage.pdf

New result:

Uploaded File Name :Coverpage.pdf

Hope it helps :)

-1

You'll need your own code running outside browser-box to do this, since browsers are designed NOT to allow this.

I mean something ugly like ActiveX, flash, COM object, custom browser extenstion or other fancy security breach that can open it's own OpenFileDialog and insert that value in your input field.

Not the answer you're looking for? Browse other questions tagged or ask your own question.