我需要知道如何将帖子图像保存到codeigniter中的文件夹
答案 0 :(得分:0)
function addImage() {
if (!is_dir('./Uploads/')) {
mkdir('./Uploads/', 0777, TRUE);
}
if (!empty($_FILES['image'])) {
$config['upload_path'] = './Uploads/';
$config['allowed_types'] = '*';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['overwrite'] = TRUE;
$config['file_name'] = date('U') . '_' . $_FILES['image']['name'];
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload('image')) {
$error = array('error' => $this->upload->display_errors());
print_r($error);
die;
} else {
if ($this->upload->do_upload('image')) {
$image_data = $this->upload->data();
$full_path = $config['file_name'];
$insert["image"] = $full_path;
$insertId = $this->data_model->add_data($insert, 'tableName');
}
}
}