In html
<input type="file" id="importFile" /> <input type="button" onclick="upload()"/><script>function upload() { var filename = document.getElementById("importFile").value; // The filename at this time is not the value in the importFile box alert(filename);}</script>As in the above code, after selecting the file using the file upload dialog box, if you select the "D://temp/file/test.txt" file, alert(filename) is "C://fakepath/test.txt" why? What should I do if I want to get the original file path and file name? Thank you in advance.
<input type="file" name="blogrollimage" onchange="setBlogrollImageName(this)" txlFillIn="isNotNull"><script type="text/javascript">function setBlogrollImageName(basicfile){document.getElementById("blogrollimagename").value=basicfile.value;}</script>When input, add onchange="setBlogrollImageName(this)" and add this section of js to the page!
Thanks to doop1120 for its reply.
I did what you said, but the result was the same. If "D://temp/file/test.txt" is selected, document.getElementById("blogrollimagename").value=basicfile.value;
The value obtained in this way is still document.getElementById("blogrollimagename").value=C://fakepath/test.txt, not what I want D://temp/file/test.txt
The reason for D://temp/file/ is the issue of ie browser security settings
Steps to resolve this issue:
Open ie browser --> internet options --> security --> custom level --> others --> enable "Show file directory path when uploading files to server"
After confirmation, just run again
The above article JS to obtain the absolute path to upload files is all the content I have shared with you. I hope you can give you a reference and I hope you can support Wulin.com more.