当我点击按钮时,它将返回错误“您没有选择要上传的文件”。和我的图像没有上传! 现在请帮帮我,我该怎么办?
我的观点是
<form action="insertform" enctype="multipart" name="form" method="post" id="contact-form" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="name">Image Upload:</label>
<div class="controls">
<input type="file" class="input-large" name="image" id="image">
</div>
<form>
我的控制器是:
public function upload()
{
$this->load->helper(array('form', 'url'));
$config['upload_path'] = FCPATH."upload";
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('xyz', $error);
} else {
$data = array('upload_data' => $this->upload->data());
$this->load->view('xyz', $data);
}
}
答案 0 :(得分:0)
我认为文件输入名称应为&#34; userfile&#34;,而不是&#34; image&#34;。
答案 1 :(得分:0)
CI文件上传文件控件默认名称为userfile
。
如果您想将其名称更改为自定义名称,则必须将新名称传递给上传功能,如:
if ( ! $this->upload->do_upload("image")) // image is your new name for file control
答案 2 :(得分:0)
首先,
将do_upload函数调用更改为:
if ( ! $this->upload->do_upload('image'))
OR
将输入名称更改为:
<input type="file" class="input-large" name="userfile" id="image">
其次,
将您的表单输入更改为:
enctype="multipart/form-data"