无法在codeigniter中上传图像文件夹

时间:2016-07-17 09:16:15

标签: codeigniter-3

我无法将图像添加到文件夹中,我不知道为什么。我的根文件夹中有客户文件夹。需要帮助。

这是我的控制器功能:

function add_new_successfully(){

$config['upload_path'] = site_url().'customer/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';

$this->load->library('upload',$config);
$this->upload->do_upload('userfile');

$data['customer_name'] = $this->input->post('c_name');
$data['customer_email'] = $this->input->post('c_email');
$data['customer_pass'] = $this->input->post('c_pass');
$data['customer_country'] = $this->input->post('c_country');
$data['customer_city'] = $this->input->post('c_city');
$data['customer_contact'] = $this->input->post('c_contact');
$data['customer_address'] = $this->input->post('c_address');
$data['customer_image'] = $_FILES['userfile']['name'];

$this->common_model->insert('customers',$data);

$this->session->set_flashdata('page_added','<div class="n_ok"><p>Customer added</p></div>');

    redirect($_SERVER['HTTP_REFERER']);
}

2 个答案:

答案 0 :(得分:1)

上传路径不是您尝试在此处设置的网址值。它是文件系统的绝对路径或相对路径。

$config['upload_path'] = FCPATH.'customer/';//FCPATH is constant for file system path to root directory or better said path to location next to index.php file

Docs

答案 1 :(得分:0)

$config['upload_path'] = './customer/';

但你需要在项目中有一个名为“customer”的文件夹。