我正在使用Jquery Ajax在Codeigniter中上传图像,但问题是图像没有上传我收到警报禁止键字符.Below是我正在使用的模型和视图。
查看:
$("#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>
型号:
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
{
}
}
}
答案 0 :(得分:1)
答案 1 :(得分:0)
试试这个
//Program a custom submit function for the form
$("form#data").submit(function(event){
//disable the default form submission
event.preventDefault();
//grab all form data
var formData = new FormData($(this)[0]);
$.ajax({
url: 'formprocessing.php',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (returndata) {
alert(returndata);
}
});
return false;
});
答案 2 :(得分:0)