Php 使用AJAX上传codeigniter文件
您好,我有一个使用AJAX的函数。我需要检索文件的名称大小类型,并且必须将其保存到数据库中 这是我的密码Php 使用AJAX上传codeigniter文件,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,您好,我有一个使用AJAX的函数。我需要检索文件的名称大小类型,并且必须将其保存到数据库中 这是我的密码 function UploadImage() { var data = new FormData($('#fileName')); Jquery.each($('#fileName')[0].files, function(i,file) { data.append(i,file); } $.ajax({ type: 'post', dat
function UploadImage() {
var data = new FormData($('#fileName'));
Jquery.each($('#fileName')[0].files, function(i,file) {
data.append(i,file);
}
$.ajax({
type: 'post',
data: data,
url: 'controller/function',
cache: false,
ContentType: false,
ProcessData: false,
success: function(data) {
alert(data);
}
}
当我通过我的控制器检索来自ajax请求的数据时,我无法使用$files[]获取文件的数据,它在说未定义索引时出错。这可能适用于您
function UploadImage()
{
var data = new FormData(document.getElementById("fileName"));//remember fileName is your form id.
//You dont need this
/*Jquery.each($('#fileName')[0].files, function(i,file) {
data.append(i,file);
}*/
//you don't need to modify the data. data already contains whole form information.
$.ajax({
type: 'post',
data: data,
url: 'controller/function',//better use full path instead of relative path
cache: false,
ContentType: false,
ProcessData: false,
success: function(data) {
alert(data);
}
}
你必须发布你的全部代码,也就是php代码。嗨,先生。我这样做了,但是当我var_转储结果时,它返回null。