这是我上传图片的视图代码,但显示错误您没有选择要上传的文件。
<form id="signupForm" action="<?php echo base_url();?>dashboard/saveSpeciality" method="post">
<div class="form-row">
<input type="text" required="" name="speciality_Name" placeholder="Speciality Name" >
<?php echo form_error('speciality_Name','<span class="help-block">','</span>'); ?>
</div>
<input type="file" name="image" size="20"/>
<?php echo form_error('image','<span class="help-block">','</span>'); ?>
<div class="form-row">
<input type="submit" name="addSubmit" value="Add Speciality"/>
</div>
</form>
这是我的控制器仪表板的代码,功能是saveSpeciality。当我尝试上传图片时,显示错误“您没有选择要上传的文件。”。
public function saveSpeciality()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
$config['max_size'] = '2048000';
$config['max_width'] = '2048';
$config['max_height'] = '2048';
$config['overwrite'] = true;
$this->load->library('upload', $config);
$imag="image";
if( ! $this->upload->do_upload($imag)){
$this->form_validation->set_error_delimiters('<p class="error">', '</p>');
echo $this->upload->file_name;
$error = array('error' => $this->upload->display_errors());
print_r($error);
} else {
$data = array('upload_data' => $this->upload->data());
}
}
答案 0 :(得分:0)
在表单中添加enctype="multipart/form-data"
属性
<form id="signupForm" action="<?php echo base_url();?>dashboard/saveSpeciality" method="post" enctype="multipart/form-data">
</form>
答案 1 :(得分:0)
您可以尝试将enctype="multipart/form-data"
添加到<form>
答案 2 :(得分:0)
试试这个
<form id="signupForm" action="<?php echo base_url();?>dashboard/saveSpeciality" method="post" enctype="multipart/form-data">
$file_name = time() . "." . pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
$config['upload_path'] = FCPATH . 'uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|GIF|JPG|PNG|JPEG';
$config['max_size'] = '2048000';
$config['max_width'] = '2048';
$config['max_height'] = '2048';
$config['file_name'] = $file_name;
$config['overwrite'] = true;
$obj->upload->initialize($config);
$imag = "image";
if (!$obj->upload->do_upload($imag)) {
$error = array('error' => $this->upload->display_errors());
print_r($error);
//return $obj->upload->display_errors();
} else {
$data = array('upload_data' => $this->upload->data());
}