0
我試圖通過ajax _call發送文件表單視圖到服務器。 這裏是我的形式:無法通過ajax調用發送文件
<form id="fileForm" name="fileForm" enctype="multipart/form-data">
<div class="row" >
<div class="span8" >
<label><strong>Please attach a file</strong></label>
<input style="margin-bottom:0" type="file" name="attach" id="attach" />
<button type="submit" class="btn btn-primary" onclick="do_upload()" ><i class="icon-camera icon-white"></i>Send</button>
</div>
</div>
</form>
這裏是do_upload(在同一個文件):
公共/小時最後(這是我的控制器),我有:
function do_upload() {
$config= array ('upload_path'=>'./uploads/','allowed_types'=>'pdf|gif|jpg|jpeg|docx', 'max_size'=>2048);
//loading upload
$this->load->library('upload', $config);
if (! $this->upload->do_upload('attach'))
{ $data = array('error' => $this->upload->display_errors());
var_dump($data);
exit;
}
else
{ $data = array('upload_data' => $this->upload->data('attach'));
var_dump($data);
exit;
}
}
這裏是後續代碼var_dump($數據)的結果:
array(1) {
["error"]=>
string(43) "<p>You did not select a file to upload.</p>"
}
而且螢火顯示了這個錯誤:
Form contains a file input, but is missing method=POST and enctype=multipart/form-data on the form. The file will not be sent.
誰能幫幫我好嗎?謝謝
以及你的錯誤說你缺少'方法= POST'表單中的聲明,有你嘗試添加這個? –
@mr_lewjam是的,我綁定添加這個,但我得到了同樣的錯誤信息 – user1499220