dongxuxian1123 2016-01-08 12:13
浏览 49

无法通过Codeigniter中的Ajax上传图像

I am using Jquery Ajax to upload an image in Codeigniter, But the problem is the image does not get uploaded an I get alert Disallowed key Characters.Below is the model and view I am using.

View:

$("#upload_course_img").on('submit',function(e){
    e.preventDefault();

 $.ajax({
    url: "<?php echo base_url();?>upload_course_image/upload_img",
        type: 'POST',
        cache: false,               
    data: new FormData(this),
        processData:false,

        success: function(data){
         alert("data:"+data);


       },
    error: function(){                      
    alert('Error while request..');
    }
   });
});

<form  method="post" id="upload_course_img" enctype="multipart/form-data"> 
<input type="file" name="course_img"/>
<input type="submit" name="submit" value="Save" id="submit-id-submit"/> 
</form>

Model:

public function upload_img()
{
  if($this->input->post('course_img')) {  

  $config['upload_path'] = './uploads/';
  $config['allowed_types'] = 'gif|jpg|png|jpeg';
  $config['max_size'] = '10000';
  $config['max_width']  = '1024';
  $config['max_height']  = '768';

  $this->load->library('upload', $config);

  if (!$this->upload->do_upload())
  {

  } 
  else
  {


  }
  }
}
  • 写回答

3条回答 默认 最新

  • duanjiong5686 2016-01-08 12:41
    关注

    this is another option to upload file using AJAX http://malsup.com/jquery/form/#file-upload

    评论

报告相同问题?

悬赏问题

  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法