繁体   English   中英

Codeigniter jQuery文件上传不起作用

[英]Codeigniter jQuery file upload not working

PHP代码:

$files = json_decode($this->input->post('Image'));
echo "<pre>";
print_r($files);
echo "</pre>";

jQuery代码:

var image = [];
for(var i = 1; i <= $("#removeimagefield").attr('data-id'); i++){
    image.push($("#imageupload"+i).val());
}
console.log(JSON.stringify(image));

HTML代码:

<form role="form" enctype="multipart/form-data" accept-charset="utf-8" name="formname" id="formname"  method="post" action="">
    <input type="file" class="default" id="imageupload1">
</form>

AJAX功能:

  addproperty = {Image: JSON.stringify(image)}
  $.ajax({
    method: "POST",
    url: formsubmission,
    data: addproperty,
    async : false,
    cache : false,
    contentType : false,
    processData : false,
    success: function(response){
      console.log(response);
    }
  });

控制台消息:

["C:\\fakepath\\abhishek.jpg","C:\\fakepath\\krunal.jpg","C:\\fakepath\\nitin.jpg"]

我正在尝试将图像文件上传到Codeigniter Controller。 但是当我打印$ files的值时。 比它显示空数组。

尝试使用此代码,并使用简单的$ _FILES ['img_file'] ['file_name']在控制器中获取文件

   $(document).ready(function (e) {
                    var file_name = $('#id_file_input').prop('files')[0];
                    var form_data = new FormData();
                    form_data.append('img_file', file_data);
                    $('#vid_file').prop('disabled', true);
                    $.ajax({
                    url: '<?php echo base_url(); ?>Controller/function_name', 
                        dataType: 'text', 
                        cache: false,
                        contentType: false,
                        processData: false,
                        data: form_data,
                        type: 'post',
                          success: function (response) {

                        }
                    });
                    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM