Codeigniters do_upload()函数不起作用 [英] Codeigniters do_upload() function is not working
问题描述
如果删除部件$this->upload->do_upload('filefoto')
,我的数据将保存到数据库中,但是图像文件不会保存到文件夹路径中.
If I remove the part $this->upload->do_upload('filefoto')
my data is saved into the database, but the image file is not saved to the folder path.
从pastebin复制
Copied from 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');
}
}
}
}
如何上传图片?
推荐答案
在共享服务器托管上,您可能需要提供完整的相对路径到您的上载文件夹.另外,请确保您拥有将文件写入该目录的所有权限!
on a shared server hosting you may need to provide the complete relative path to your upload folder. Also make sure you have all permissions to write a file to that directory!
您可以在localhost环境上使用
you can use on a localhost environment
$config['upload_path'] = './assets/upload';
但是在共享主机上,您需要获得更具体的信息,通常是类似
but on a shared hosting, you'll need to get more specific, normally something like
$config['upload_path'] = '/home/yourserver/public_html/assets/upload';
您可以找到此upload_path,例如在帐户的cPanel主页的左列中,或者可能要致电提供商的帮助台以获取有关正确路径的更多信息.
You can find this upload_path, e.g. in your accounts cPanel main page on the left column or might want to call your provider's helpdesk for more info on the correct path.
这篇关于Codeigniters do_upload()函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!