Codeigniters do_upload() 函数不起作用
Codeigniters do_upload() function is not working
如果我删除部分 $this->upload->do_upload('filefoto')
我的数据会保存到数据库中,但图像文件不会保存到文件夹路径中。
从 pastebin 复制
public function tambahanggota() {
$this->load->library('upload');
$nmfile = "file_".time();
$config['upload_path'] = './assets/uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
$config['max_size'] = '3072';
$config['max_width'] = '5000';
$config['max_height'] = '5000';
$config['file_name'] = $nmfile;
$this->upload->initialize($config);
if($_FILES['filefoto']['tmp_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;
$config2['height'] = 100;
$this->load->library('image_lib',$config2);
if ($res>=1) {
echo "<script>alert('Data berhasil disimpan')</script>";
echo "<script>window.location='".base_url()."dataanggota'</script>";
}
else{
$this->session->set_flashdata('pesan', 'Maaf, ulangi data gagal di inputkan.');
redirect('dashboard/index');
}
}
}
}
如何上传图片?
在托管共享服务器上,您可能需要提供上传文件夹的完整相对路径。还要确保您拥有向该目录写入文件的所有权限!
您可以在本地主机环境中使用
$config['upload_path'] = './assets/upload';
但在共享主机上,您需要更具体一些,通常类似于
$config['upload_path'] = '/home/yourserver/public_html/assets/upload';
您可以找到这个 upload_path,例如在您的帐户 cPanel 主页左栏中,或者可能想致电您的提供商的服务台以获取有关正确路径的更多信息。
你错过了这个
$this->upload->upload_path.'/'.$this->upload->file_name;
如果我删除部分 $this->upload->do_upload('filefoto')
我的数据会保存到数据库中,但图像文件不会保存到文件夹路径中。
从 pastebin 复制
public function tambahanggota() {
$this->load->library('upload');
$nmfile = "file_".time();
$config['upload_path'] = './assets/uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|bmp';
$config['max_size'] = '3072';
$config['max_width'] = '5000';
$config['max_height'] = '5000';
$config['file_name'] = $nmfile;
$this->upload->initialize($config);
if($_FILES['filefoto']['tmp_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;
$config2['height'] = 100;
$this->load->library('image_lib',$config2);
if ($res>=1) {
echo "<script>alert('Data berhasil disimpan')</script>";
echo "<script>window.location='".base_url()."dataanggota'</script>";
}
else{
$this->session->set_flashdata('pesan', 'Maaf, ulangi data gagal di inputkan.');
redirect('dashboard/index');
}
}
}
}
如何上传图片?
在托管共享服务器上,您可能需要提供上传文件夹的完整相对路径。还要确保您拥有向该目录写入文件的所有权限!
您可以在本地主机环境中使用
$config['upload_path'] = './assets/upload';
但在共享主机上,您需要更具体一些,通常类似于
$config['upload_path'] = '/home/yourserver/public_html/assets/upload';
您可以找到这个 upload_path,例如在您的帐户 cPanel 主页左栏中,或者可能想致电您的提供商的服务台以获取有关正确路径的更多信息。
你错过了这个
$this->upload->upload_path.'/'.$this->upload->file_name;