gpt4 book ai didi

javascript - 将文件内容存储在表中(html table tr td) jquery

转载 作者:行者123 更新时间:2023-12-01 05:43:36 25 4
gpt4 key购买 nike

我想通过将每个文件内容上传/添加到表中来在数据库中插入多个文件,然后将所有文件添加到表中后,我添加表的值,包括我传递给ajax的表单数据中的文件内容。我试过了

var file = $('#file')[0].files[0];
//var file = document.getElementById('file').files[0];
var name = file.name;
var size = file.size;
var type = file.type;
var blob = new Blob([file], {
type: "application/octet-binary"
});
var filecontent = blob;

Here i used the value of filecontent to be passed to ajax but in php the condition if(!empty($_FILES) remaind false)

在console.log文件内容看起来像[object Blob]我想做的是实现我的主要目标,即存储到数据库,我已经问过一个关于它的问题。可以找到我here这就是我问第一个问题的原因。

我的问题是如何将文件内容存储到变量中,在本例中存储 $('#file')[0].files[0] 的值至file .

UPDATE

当我使用 var file = $('#file')[0].files[0]; 的值时我仍然遇到同样的错误

UPDATE

是否可以存储 input:file进入table tdinputany other element并在需要时重用该文件

最佳答案

要将文件内容存储到变量中,您首先需要读取它们,因此您必须使用 FileReader

例如readAsText()方法语法:

instanceOfFileReader.readAsText(blob[, encoding]);

The readAsText method is used to read the contents of the specified Blob or File. When the read operation is complete, the readyState is changed to DONE, the loadend is triggered, and the result attribute contains the contents of the file as a text string.

因此您可以将结果存储到变量中。

关于javascript - 将文件内容存储在表中(html table tr td) jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29179236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com