我在提交按钮时插入数据时遇到问题,图片上传失败。
我试了好几次但都失败了。如何成功上传图像并存储 所以这里是我的代码:
我的控制器:
public function savedosen() {
$this->load->library('upload');
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
$config['max_size'] = '2048';
$config['max_width'] = '1288';
$config['max_height'] = '768';
$this->upload->initialize($config);
if ($this->upload->do_upload('foto'))
{
$gambar = $this->upload->data();
$nik = $this->input->post('nik');
$nama = $this->input->post('nama_dosen');
$jk = $this->input->post('jk');
$agama = $this->input->post('agama');
$tempat = $this->input->post('tempat');
$title = $this->input->post('title');
$status = $this->input->post('status');
$prodi = $this->input->post('prodi');
$password = $this->input->post('confirm_password');
$data = array(
'nik_dosen' =>$nik,
'nama_dosen' => $nama,
'jenis_kelamin' => $jk,
'agama' => $agama,
'tempat_lahir' =>$tempat,
'status' => $status,
'title_dosen' => $title,
'foto_dosen' => $gambar['file_name'],
'pass_dosen' => md5($password),
'id_prodi' => $prodi,
);
$this->dosen_model->insertdosen($data);
redirect('dosen');
}
else
{
echo "Gagal";
}}
我的观点:
<div class="form-group ">
<label for="firstname" class="control-label col-lg-2">Upload Gambar
<span class="required"> * </span></label>
<div class="col-lg-6">
<input class=" form-control" id="foto" name="foto" type="file" />
</div>
</div>
帮我解决。
答案 0 :(得分:-1)
更改
$this->load->library('foto');
到
$this->load->library('upload', $config);