以下是我的代码。我想在目录中保存图片。数据到数据库正确但目录为空。以下是我的控制代码,请检查并帮助我。
public function addMakupTips()
{
$this->load->model('makuptipsmodel');
//Uploading data
$config = array(
'upload_path' => "./makupimages",
'allowed_types' => 'jpg|png|jpeg',
'overwrite' => TRUE,
'encrypt_name' => TRUE,
);
$this->load->library('upload', $config);
$files = $_FILES['uploads'];
foreach ($files['name'] as $key => $filename) {
$_FILES['uploads[]']['name'] = $files['name'][$key];
$_FILES['uploads[]']['type'] = $files['type'][$key];
$_FILES['uploads[]']['tmp_name'] = $files['tmp_name'][$key];
$_FILES['uploads[]']['error'] = $files['error'][$key];
$_FILES['uploads[]']['size'] = $files['size'][$key];
$config['file_name'] = $filename;
$this->upload->initialize($config);
$uploads[] = $this->upload->data();
$array = array(
'name' => $this->input->post('name'),
'category' => $this->input->post('category'),
'title' => $this->input->post('title'),
'poetry' => $this->input->post('poetry'),
'keywords' => $this->input->post('keywords'),
'image' => $_FILES['uploads[]']['name']
);
$this->makuptipsmodel->addData($array);
redirect(base_url() . 'admin/makuptips/index/' . $record_id);
//Uploading end
}
}
在上面的代码中,我试图将完整的表单数据保存在带有图片的数据库中。这是我的表单屏幕短
答案 0 :(得分:1)
为防止从用户指南中复制和粘贴,您应该再次阅读...
https://www.codeigniter.com/userguide3/libraries/file_uploading.html#the-controller
您的代码似乎缺少do_upload调用...
$this->upload->do_upload() // See the user guide