Get Absolutepath from input type="file"

Asked

Viewed 2,513 times

2

I am trying to get the complete path of the directory through the file type input, but so far I can only get a previous folder, for example, I have the folder in the C:/user/Documents/Images/Yesterday then I would like to take this whole way, but I can only get the briefcase yesterday, the code I’m making is

$('#pasta').change(
    function absolutepath(e){   
    var aqrs;
    var theFiles = e.target.files;
    alert(theFiles[0].webkitRelativePath);
});

With this code above it grab the first file with the folder with the input below:

<input type="file" id="pasta"  multiple webkitdirectory />

How do I take it all the way?

1 answer

4


Is not possible.

For security measure browsers do not allow you to know the Absolute Path of the user file.

And you can only view the previous folder name because the property webkitdirectory returns the relative path of your folder.

Give according to the specification of the HTML5, an upload control no should reveal the actual path of the selected file. 1

1 THE MYSTERY OF C: FAKEPATH UNVEILED

  • Actually, I’m going through something similar. I’m uploading with image resizing, I need to throw the path of this image into an input, and I’m struggling to do that. Is there another way? Something that can be done? @Laerte, what’s your suggestion?

  • Unfortunately this is a limitation imposed by the specification and implemented by the browsers, it is a security measure there is nothing we can do, but in your case you want to replicate the image sent by the user to another input?

  • The images go to a server folder, the file name is an md5. I need the path to save to the bank. That path, I throw in input. In the other system that I used, the image appeared, I clicked with the right button and took the path of the image. But I don’t want it to be like this, I prefer automatic, the user ends up getting lost in simple things...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.