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 选项-->安全-->自定义级别-->其他-->将"将文件上载到服务器时显示文件目录路径"启用

  • 相关阅读:
    归一化与标准化区别
    pytorch进行mnist识别实战
    pytorch实现学习率衰减
    RNN
    Python中9大时间序列预测模型
    InfluxDB基本概念
    如何在CentOS 7上使用InfluxDB分析系统指标(转载学习用)
    InfluxDB1.2.4部署(centos7)
    Centos7搭建influxdb+chronograf
    python通过SNMP协议收集服务器监控信息
  • 原文地址:https://www.cnblogs.com/wpcnblog/p/13385918.html
Copyright © 2011-2022 走看看