我用php制作了一个表单,其中一个表单内容是上传图片功能。
当我在localhost中运行表单时,数据已成功存储在我的数据库中,但是当我尝试通过主机时,表单无法将数据存储在数据库中。
源控制器:
$this->load->library('upload');
$nmfile = "file_".time(); //nama file saya beri nama langsung dan diikuti fungsi time
$config['upload_path'] = './assets/uploads/'; //path folder
$config['allowed_types'] = 'gif|jpg|png|jpeg|bmp'; //type yang dapat diakses bisa anda sesuaikan
$config['max_size'] = '3072'; //maksimum besar file 3M
$config['max_width'] = '5000'; //lebar maksimum 5000 px
$config['max_height'] = '5000'; //tinggi maksimu 5000 px
$config['file_name'] = $nmfile; //nama yang terupload nantinya
$this->upload->initialize($config);
if($_FILES['filefoto']['name'])
{
if ($this->upload->do_upload('filefoto'))
{
$gbr = $this->upload->data();
$data = array(
'nm_gbr' =>$gbr['file_name']
);
$res = $this->M_tambahdata->tambahdata("anggota",$data);
$config2['image_library'] = 'gd2';
$config2['source_image'] = $this->upload->upload_path.$this->upload->file_name;
$config2['new_image'] = './assets/hasil_resize/';
$config2['maintain_ratio'] = TRUE;
$config2['width'] = 100; //lebar setelah resize menjadi 100 px
$config2['height'] = 100; //lebar setelah resize menjadi 100 px
$this->load->library('image_lib',$config2);
if ($res>=1) {
echo "<script>alert('Data berhasil disimpan')</script>";
echo "<script>window.location='".base_url()."tambahdata'</script>";
}
else{
$this->session->set_flashdata('pesan', 'Maaf, ulangi data gagal di inputkan.');
redirect('dashboard/index');
}
}
}
}
来源观点:
<h5>Foto</h5>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-picture"></i></span>
<input name="filefoto" type="file" class="form-control">
</div>
</div><!-- /.box-body -->
</div><!-- /.box -->
答案 0 :(得分:0)
我认为你的道路是错误的。
此:
$config['upload_path'] = './assets/uploads/';
要:
$config['upload_path'] = 'assets/uploads/';
而且:
$config2['new_image'] = './assets/hasil_resize/';
要:
$config2['new_image'] = 'assets/hasil_resize/';