Absolute path to file on input[type=file]

独自空忆成欢 提交于 2020-01-06 10:46:05

问题


Is is possible to get the ABSOLUTE path to a file using javascript or jquery? These are my trials so far but the closest I can get is just the filename.

    var filepath = $('input[type=file]').val();
    var test = this.files;
    var test2 = test[0];
    var test3 = test2.fileName;
    var test4 = test2.filePath;
    var test5 = test2.Name;
    var h = imageInput.value;
    var b = document.getElementById("AcademicPhotoId");
    var l = b.value;
    var binary = b.getAsBinary();
    $('.image-display img').attr('src', filepath);

回答1:


No, that would be a security violation. (It could tell you the user's name, etc. i.e. c:\Users\Kirk\Desktop\uploadedfile.txt)

Out of curiosity, why do you desire this information?




回答2:


According to the specifications of HTML5, a file upload control should not reveal the real local path to the file you have selected, if you manipulate its value string with JavaScript. Instead, the string that is returned by the script, which handles the file information is c:\fakepath



来源:https://stackoverflow.com/questions/6866309/absolute-path-to-file-on-inputtype-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!