0

I want to find path of file and for this I am using

$('#changefilename')[0].files[0].path

inside jquery but I am finding Undefined, Although I am using same process some place and finding desired output correctly but at this place I am finding wrong output.
Jsfiddle

if someone is familiar with this problem then Kindly help me.

2 Answers2

0

There is no path property for the File object. You can only get the path of the file relative to the site's URL.

There are the available properties.

  • File.lastModified (Read only)

    Returns the last modified time of the file, in millisecond since the UNIX epoch (January 1st, 1970 at Midnight).

  • File.lastModifiedDate (Read only)

    Returns the last modified Date of the file referenced by the File object.

  • File.name (Read only)

    Returns the name of the file referenced by the File object.

  • File.webkitRelativePath Read only)

    Returns the path the URL of the File is relative to.

File implements Blob, so it also has the following properties available to it:

  • File.size (Read only)

    Returns the size of the file.

  • File.type (Read only)

    Returns the MIME type of the file.

Community
  • 1
  • 1
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
0

You can't do what you're asking for.

Let's take a look on your file object:

console.log($('#changefilename')[0].files[0]);

(Took the first random file on my desktop)

File { name: "XXXXX", lastModified: XXXXX, lastModifiedDate: XXXXX, webkitRelativePath: "", size: XXXXX, type: "application/XXXXX" }

Due to security reasons a full path from your PC is not included in file informations.

Mavin
  • 64
  • 4
  • then can you tell me the way that I can be able to perform operations on browse file. – Dheeraj Kumar Nov 07 '17 at 01:55
  • What kind of operation do you need to do? If you need to upload it you have to send POST request using a form with `enctype="multipart/form-data"` enabled to a script (PHP, Ruby or whatever you're using). I don't think there's anything else to do with a file. – Mavin Nov 07 '17 at 12:06