Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用AJAX上传codeigniter文件_Php_Jquery_Ajax_Codeigniter - Fatal编程技术网

Php 使用AJAX上传codeigniter文件

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

您好,我有一个使用AJAX的函数。我需要检索文件的名称大小类型,并且必须将其保存到数据库中

这是我的密码

 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。