我有一个codeigniter应用程序,每次你去页面时,都说你没有选择要上传的文件。我正在使用与页面显示相同的codeigniter函数作为文件句柄上传。
我正在使用ajax提交表单,所以我无法检查$ _SERVER ['REQUEST_METHOD']
以下是我的功能片段:
if(!$this->upload->do_upload('userFile')) { // if there are errors uploading the file of if it's the first time on the page…
$content_data['album'] = $album;
echo "post go through?";
// if the $_POST array is not empty display the error. That means that someone submitted the form without choosing a file
//if(isset($_POST['submit'])) {
$content_data['error'] = array('error' => $this->upload->display_errors());
//}
$content_data['data'] = array('upload_data'=>$this->upload->data());
$data['sess'] = $this->session;
$data['content'] = $this->load->view('member/addPhoto', $content_data, true);
$this->load->view('template/admin', $data);
} else { // else there were no errors and we can resize and upload.
}
答案 0 :(得分:1)
在执行上述操作之前,您可以检查是否已提交
if ($this->input->post('userFile'))
{
// Your code
}