2

I have a select choice of files to upload can be single or multiple as I select I would like to have a text below stated the path of the files I have selected.

 <form action="mymethod" enctype="multipart/form-data" method="Post"     id="submitForm">
<input id="file" name="file[]" multiple type="file">

Upon selecting the file let say its 3:

enter image description here

it will show on the screen:

enter image description here

however currently it is showing:

enter image description here

here is my script:

<script>
                    var selDiv = "";

                    document.addEventListener("DOMContentLoaded", init,
                            false);

                    function init() {
                        document.querySelector('#file').addEventListener(
                                'change', handleFileSelect, false);
                        selDiv = document.querySelector("#selectedFiles");
                    }

                    function handleFileSelect(e) {

                        if (!e.target.files)
                            return;

                        selDiv.innerHTML = "";

                        var files = e.target.files;
                        for ( var i = 0; i < files.length; i++) {
                            var f = files[i];

                            selDiv.innerHTML += f.name + "<br/>";

                        }

                    }
</script>

Prehaps you guys could give me suggestion on how I would tackle this issue?

isme
  • 157
  • 2
  • 2
  • 16

1 Answers1

1

You won't be able to access this via JavaScript; as a security precaution the browser will expose the file name to you, but nothing else about the local file system.

This is a built in security measure by the browser creators, so private information about local file paths cannot be seen.

Psylogic
  • 2,494
  • 1
  • 16
  • 36