Php Codeigniters do_upload()函数不工作
如果我删除部件Php Codeigniters do_upload()函数不工作,php,codeigniter,image-uploading,Php,Codeigniter,Image Uploading,如果我删除部件$this->upload->do_upload('filefoto')我的数据将保存到数据库中,但图像文件不会保存到文件夹路径中 从pastebin复制 public function tambahanggota() { $this->load->library('upload'); $nmfile = "file_".time(); $config['upload_path'] = './assets/uploa
$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');
}
}
}
}
公共函数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);
如果($_FILES['filefoto']['tmp_name'])
{
如果($this->upload->do_upload('filefoto'))
{
$gbr=$this->upload->data();
$data=数组(
'nm_gbr'=>$gbr['file_name']
);
$res=$this->M_tambahdata->tambahdata(“anggota”,$data);
$config2['image_library']='gd2';
$config2['source\u image']=$this->upload->upload\u path.$this->upload->file\u name;
$config2['new_image']='./assets/hasil_resize/';
$config2['maintain_ratio']=TRUE;
$config2['width']=100;
$config2['height']=100;
$this->load->library('image_lib',$config2);
如果($res>=1){
回声“警报(‘数据错误’)”;
echo“window.location=”.base_url()“dataanggota';
}
否则{
$this->session->set_flashdata('pesan','Maaf','ulangi data gagagal di inputkan');
重定向(“仪表板/索引”);
}
}
}
}
如何上传图像?在托管图像的共享服务器上,您可能需要提供上传文件夹的完整相对路径。还要确保您拥有将文件写入该目录的所有权限 您可以在本地主机环境上使用
$config['upload_path'] = './assets/upload';
但在共享主机上,您需要更加具体,通常是
$config['upload_path'] = '/home/yourserver/public_html/assets/upload';
您可以找到此上载路径,例如,在您的帐户cPanel主页的左栏中,或者您可能希望致电提供商的帮助热线以获取有关正确路径的更多信息。在托管的共享服务器上,您可能需要提供上载文件夹的完整相对路径。还要确保您拥有将文件写入该目录的所有权限 您可以在本地主机环境上使用
$config['upload_path'] = './assets/upload';
但在共享主机上,您需要更加具体,通常是
$config['upload_path'] = '/home/yourserver/public_html/assets/upload';
您可以找到此上载路径,例如,在您的帐户cPanel主页的左栏中,或者您可能希望致电提供商的帮助热线以获取有关正确路径的更多信息。您错过了此路径
$this->upload->upload_path.'/'.$this->upload->file_name;
你错过了这个
$this->upload->upload_path.'/'.$this->upload->file_name;
看这个,;不工作,可以保存到数据库中,但文件夹路径为emptylocalhost或public(shared)server?在视图中,您是否使用了codeigniter form helper
form\u open\u multipart('controller/function')
并尝试if(isset($\u FILES){…}
@Vickel public(shared)服务器看到这个;不工作,可以保存到数据库中,但文件夹路径为emptylocalhost或公共(共享)服务器?在视图中,您是否使用了codeigniter form helperform\u open\u multipart('controller/function')
并尝试if(isset($\u FILES){…}
@Vickel public(共享)服务器