Get url file upload javascript

How to get full path of file while selecting file using <input type=‘file’>

<input type="file" id="fileUpload">
<script type="text/javascript">
function getFilePath(){
     $('input[type=file]').change(function () {
         var filePath=$('#fileUpload').val(); 

but the filePath var contains only name of selected file, not the full path.
I searched it on net, but it seems that for security reasons browsers (FF,chrome) just give name of file.
Is there any other way to get full path of
selected file?

asked Mar 4, 2013 at 11:59

Get url file upload javascript

PingleYogesh Pingle

3,3953 gold badges15 silver badges16 bronze badges


For security reasons browsers do not allow this, i.e. JavaScript in browser has no access to the File System, however using HTML5 File API, only Firefox provides a mozFullPath property, but if you try to get the value it returns an empty string:

$('input[type=file]').change(function () {

So don’t waste your time.

If you need the file’s path for reading a file you can use the FileReader API instead. Here is a related question on SO: Preview an image before it is uploaded.

Get url file upload javascript


18.3k10 gold badges32 silver badges49 bronze badges

answered Mar 4, 2013 at 12:09


141k16 gold
164 silver badges192 bronze badges


Try This:

It’ll give you a temporary path not the
accurate path, you can use this script if you want to show selected images as in this jsfiddle example(Try it by selectng images as well as other files):-


Here is the code :-


<input type="file" id="i_file" value=""> 
<input type="button" id="i_submit" value="Submit">
<img src="" width="200" style="display:none;" />
<div id="disp_tmp_path"></div>


$('#i_file').change( function(event) {
    var tmppath = URL.createObjectURL([0]);
    $("#disp_tmp_path").html("Temporary Path(Copy it and try pasting it in browser address bar) --> <strong>["+tmppath+"]</strong>");

Its not exactly what you were looking for, but may be it can help you somewhere.

Get url file upload javascript


Xem thêm:  Tuổi 87 và 88 có hợp làm ăn không

18.3k10 gold badges32 silver badges49 bronze badges

Jul 18, 2014 at 6:07

Get url file upload javascript


2,2121 gold badge13 silver badges15 bronze badges


cannot do so – the browser will not allow this because of security concerns.

When a file is selected by using the input type=file object, the value of the value property depends on the value of the “Include local directory path when uploading files to a server” security setting for the security zone used to display the Web page containing the input object.

The fully qualified filename of the selected file is returned only when this setting is enabled. When the setting is
disabled, Internet Explorer 8 replaces the local drive and directory path with the string C:\fakepath\ in order to prevent inappropriate information disclosure.

And other

You missed ); this at the end of the change event function.

Also do not create function for change event instead just use it as below,

<script type="text/javascript">

        $('#fileUpload').on('change',function ()
            var filePath = $(this).val();


answered Mar 4, 2013 at 12:05

Dipesh ParmarDipesh Parmar

26.8k7 gold badges59 silver badges87 bronze badges


can’t. Security stops you for knowing anything about the filing system of the client computer – it may not even have one! It could be a MAC, a PC, a Tablet or an internet enabled fridge – you don’t know, can’t know and won’t know. And letting you have the full path could give you some information about the client – particularly if it is a network drive for example.

Xem thêm:  Hướng dẫn dùng plotly colors python

In fact you can get it under particular conditions, but it requires an ActiveX control, and will not work in 99.99% of

You can’t use it to restore the file to the original location anyway (as you have absolutely no control over where downloads are stored, or even if they are stored) so in practice it is not a lot of use to you anyway.

answered Nov 22, 2013 at 5:47

Get url file upload javascript

Rajshekar ReddyRajshekar Reddy

18.2k3 gold badges37 silver badges59 bronze badges

You can use the following code to get a working local URL for the uploaded file:

<script type="text/javascript">    
    var path = (window.URL || window.webkitURL).createObjectURL(file);
    console.log('path', path);

answered Mar 30, 2016 at 14:26

Steffen BremSteffen Brem

1,72018 silver badges28 bronze badges

Did you mean this?

$('#i_file').change( function(event) {
var tmppath = URL.createObjectURL([0]);
Get url file upload javascript


18.5k10 gold badges42 silver badges60 bronze badges

Nov 23, 2014 at 19:10

Aytac GulAytac

1851 silver badge2 bronze badges


interesting note: although this isn’t available in on the web, if you’re using JS in Electron then you can do this.

Using the standard HTML5 file input, you’ll receive an extra path property on selected files, containing the real file path.

Full docs here:

answered Nov 18, 2019 at 14:23

Tim PerryTim Perry

10.5k1 gold badge50 silver badges78 bronze badges

You can, if uploading an entire folder is an
option for you

<input type="file" webkitdirectory directory multiple/>

change event will contain:

.target.files[...].webkitRelativePath: "FOLDER/FILE.ext"

but it doesn’t contain the whole absolute path, only the relative one. Supported in Firefox also.

Xem thêm:  Hướng dẫn dùng double colon trong PHP

answered Mar 4, 2017 at 9:31


9,3978 gold badges61 silver badges91 bronze badges

file element has and array call files it contain all necessary stuff you need

var file = document.getElementById("upload");

file.addEventListener("change", function() {
    for (var i = 0; i < file.files.length; i++) {
}, false);

answered Dec 13, 2017 at 7:56

Jeeva KumarJeeva Kumar

3332 silver badges8 bronze badges


$('input[type=file]').change(function () {

This is the correct form.

answered Aug 1, 2021 at 13:57

Get url file upload javascript


731 silver badge7 bronze badges


You can get the full path of the selected file to upload only by IE11 and MS Edge.

var fullPath = Request.Form.Files["myFile"].FileName;

answered Apr 1, 2019 at 11:03

Get url file upload javascript

Majid ShahabfarMajid Shahabfar

2,8291 gold badge25 silver badges34 bronze badges

Not the answer you’re looking for? Browse other questions tagged javascript
jquery file-upload
filepath or ask your own question.

Thuộc website

Related Posts