开发者

HTML file attribute issue

开发者 https://www.devze.com 2023-02-07 10:11 出处:网络
<input type=\"file\" id=\"file-id\" /> &l开发者_运维问答t;input type=\"text\" name=\"file_path\" id=\"file-path\">
<input type="file" id="file-id" />
&l开发者_运维问答t;input type="text" name="file_path" id="file-path">

in jquery:

$("#file-path").val($("#file-id").val());
gives me : - 'C:\\fakepath\\test.py'

I am using ubuntu as my operating system. If I selected a file from /home/mylappy/Document/test.py It shows me the file path 'C:\\fakepath\\test.py'


For historical reasons, the value IDL attribute prefixes the filename with the string "C:\fakepath\". Some legacy user agents actually included the full path (which was a security vulnerability). As a result of this, obtaining the filename from the value IDL attribute in a backwards-compatible way is non-trivial. The following function extracts the filename in a suitably compatible manner: http://www.w3.org/TR/html5/number-state.html#file-upload-state

0

精彩评论

暂无评论...
验证码 换一张
取 消