我有一个应用程序允许用户通过Web界面将一些文本数据保存到MYSQL数据库中。另外,他们还可以将文件附加到该文本中,并将其保存到blob字段中。附加的文件类型是简单的.txt文件。使用PHP和JavaScript读取blob数据
我能够将这些数据保存到数据库中,但我无法检索它。这是我在做什么,现在找回它:
//Events that take place when trying to retreive an attached file
function getFile(rowid){
//Make an AJAX Request to fetch the file
$.ajax({
type: 'get',
url: 'point-of-contact.php',
data: 'page=attachment&row='+rowid,
dataType: 'text',
success: function(data) {
console.log (data);
}
});
}
以上的AJAX请求导致了下面的PHP代码:
$attachments = $poc -> getPOC($_GET['row']);
header('Content-type: text/plain');
echo $attachments;
我所面临的问题是,当我控制台登录接收到的数据从AJAX请求我得到这个:
我如何去在简单的文本格式获取数据?
难道是我上传文件到数据库的方式不正确?这是如何将文件上传到数据库:
//File upload code
var fileInput = document.getElementById('upload');
var file = fileInput.files[0];
//Hide the save button
$("#save-button-1").hide();
//Make the AJAX request
$.ajax({
type: 'post',
url: 'point-of-contact.php?page=add',
data: 'point_of_contact=' + $("#textarea1").val() + '&point_of_contact_attachment=' + file,
success: function(data) {
$('#done-1').show();
setTimeout(function() {
$('#done-1').fadeOut();
}, 2500);
$('.loader').fadeOut();
}
});
为什么不把附件保存在那个大文件数据库(*你的文件系统*)中,并将它存储在MySQL中可以找到它的路径?你知道,正确的工具等正确的工具等 – eggyal
也应该通过$ _GET ['row']',所以你最终不会得到一个SQL注入。 – devsnd
@twall它在我的模型中被消毒。 – karancan