Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the full path of the file from a file input [duplicate]

Tags:

Possible Duplicate:
Full path from file input using jQuery

I have the following html element

<input type="file" id="upload"> 

If I use

$("#upload").val(); 

I only the file name, not the complete absolute path of the file. Can someone tell me how do get the complete path?

like image 523
Vidya Avatar asked Nov 14 '10 05:11

Vidya


People also ask

How do I get the full path of a file?

Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).

How do I get the original path instead of Fakepath?

If you go to Internet Explorer; Tools; Internet Option; Security; Custom; find the "Include local directory path when uploading files to a server" (it is quite a ways down) and click on "Enable" You may have to restart your computer, but this works & eliminates that "fakepath" that inhibits the upload file path.

How do I get the full path of an uploaded file in Python?

To get current file's full path, you can use the os. path. abspath function. If you want only the directory path, you can call os.

How do I get the value of an input type file?

The value property returns the path or the name of the file selected with the <input type="file"> element. This property returns the name of the selected file with a fake path in IE, Google Chrome, and Opera, and the name of the selected file in Firefox and Safari.


1 Answers

You cannot do so - the browser will not allow this because of security concerns. Although there are workarounds, the fact is that you shouldn't count on this working. The following Stack Overflow questions are relevant here:

  • full path from file input using jquery
  • How to get the file path from HTML input form in Firefox 3

In addition to these, the new HTML5 specification states that browsers will need to feed a Windows compatible fakepath into the input type="file" field, ostensibly for backward compatibility reasons.

  • http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-March/018981.html
  • The Mystery of c:\fakepath Unveiled

So trying to obtain the path is worse then useless in newer browsers - you'll actually get a fake one instead.

like image 80
Yi Jiang Avatar answered Sep 24 '22 15:09

Yi Jiang