当我将路径粘贴到文本框中并单击文件读取按钮时,我正在尝试读取文件。问题是它没有读取——但是对于带有文件选项的输入标签,它正在读取。
你们能告诉我如何实现吗?在下面提供我的代码。
https://codepen.io/texirv/pen/dzwrqM?editors=1111
<input class="laptop" placeholder="Paste link here to upload document." type="text" name="sportsBox" id="sportsBox">
$("#swimmingLink").click(function() {
console.log("inside click function--->" );
playerValue = $("#sportsBox").val().replace(/\\/g,"/");
var coffee = playerValue.substring(playerValue.lastIndexOf('/')+1)
console.log("playerValue--->" + playerValue);
console.log("coffee--->" + coffee);
//var myReader: FileReader = new FileReader();
var myReader = new FileReader();
//var textType = /text.*/;
var file = playerValue.files[0];
console.log("file---->" + file);
最佳答案
抱歉,出于安全原因,这无法实现。
只有在用户自己选择文件时才能获取文件。
否则,任何人都可以从控制台运行一些简单的脚本,将数以千计的恶意文件上传到您的应用程序/服务器上。这就是为什么您需要带有类型文件的输入。
关于javascript - 从文本框中读取文件而不在输入标签中给出文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45986901/