js如何读取服务器端文件目录

js如何读取服务器端文件目录,第1张

1、先准备一个json文件

2、使用vscode创建一个html文件。

3、开始撰写js方法,使者带用原生javascript来处理,先处理读取宴嫌罩json文件,之后运行这个html。

4、得到的json就是我们index.json文件中的内容。

5、为了便于查看我们json文件的晌闹内容显示在html网页中。

javascript获取<input type="file" />悔此笑文件的路径

function getPath(obj) {

if (obj) {

if (window.navigator.userAgent.indexOf("MSIE"扒手) >= 1) {

obj.select()

return document.selection.createRange().text

}

else if (window.navigator.userAgent.indexOf("碧含Firefox") >= 1) {

if (obj.files) {

return obj.files.item(0).getAsDataURL()

}

return obj.value

}

return obj.value

}

}

<script>  

      $("input[name=fileString]").change(function() {  

         //var names = []  

  

         for 并仔慎(var i = 0 i < $(this).get(0).files.length ++i) {  

            // names.push($(this).get(0).files[i].name)  

    //console.log($(this).get(0).files[i].mozFullPath)  

    //方式一:  

    var filePath = $(this).val()  

    console.log(filePath)  

    //方式二:  

    alert($('input[type=file]').val())  

         }  

         //console.log(names)  

//方式三:  

alert($("input[name=fileString]").val())  

  

     })  

    戚枯   

 </script>

注意:以上方式取到的都是文件的伪路径,由于浏览器的安全策略,Chrome浏览器及Chrome内核的浏览器是不可能获取文件在本地的真实路径的。IE浏览器可以通过设置安全级别,能获绝敬取到真实路径。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/tougao/12232415.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-22
下一篇2023-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存