zoukankan      html  css  js  c++  java
  • js获取上传文件的绝对路径

    在html中

    <input type="file" id="importFile" />
    <input type="button" onclick="upload()"/>
    
    <script>
    function upload() {
        var filename = document.getElementById("importFile").value;
        // 这时的filename不是 importFile 框中的值
        alert(filename);
    }
    </script>

    如上面的代码,用文件上传对话框选择文件后,如果选择"D:\tempfile est.txt"文件,alert(filename)却是"C:\fakepath est.txt"这是为什么?我想要取得原本的文件路径及文件名,应该怎么办?先谢谢各位了。

    <input type="file" name="blogrollimage" onchange="setBlogrollImageName(this)"  txlFillIn="isNotNull" title="链接图片">
    
    <script type="text/javascript">
    function setBlogrollImageName(basicfile){
    document.getElementById("blogrollimagename").value=basicfile.value;
    }
    </script>

    input的时候把onchange="setBlogrollImageName(this)"  加上,再把这段js加到页面即可!

    感谢doop1120的回复。
    我按您说的做了,不过,结果还是一样。如果选择"D:\tempfile est.txt",document.getElementById("blogrollimagename").value=basicfile.value;
    这样获取的值仍然是document.getElementById("blogrollimagename").value=C:\fakepath est.txt,而不是我想要的D:\tempfile est.txt

    出现D:\tempfile的原因是ie浏览器安全设置的问题
    解决此问题的步骤:
    打开ie浏览器-->internet 选项-->安全-->自定义级别-->其他-->将"将文件上载到服务器时显示文件目录路径"启用

  • 相关阅读:
    第一次讲课
    请允许我悄悄的爱你一次好吗 zz
    装.NET实在是一种折磨,
    第一次听课
    路,在何方?
    UNION和UNION ALL 的区别
    利用jquery操作select下拉列表框
    理解 collate Chinese_PRC_CI_AS
    sql 中 case when 实例
    sql 中 case when 实例(2)
  • 原文地址:https://www.cnblogs.com/wpcnblog/p/13385918.html
Copyright © 2011-2022 走看看