【问题标题】:PHP Codeigniter - How to save image to a folderPHP Codeigniter - 如何将图像保存到文件夹
【发布时间】:2019-06-22 11:35:43
【问题描述】:

我需要知道,如何将帖子图像保存到 codeigniter 中的文件夹

【问题讨论】:

  • 您尝试过什么,您使用的是什么版本的 codeigniter?
  • 您要做的第一件事是访问文档或有关如何执行此操作的众多教程中的任何一个

标签: php codeigniter


【解决方案1】:
 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');

        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-23
    • 2016-03-09
    • 1970-01-01
    • 2018-03-24
    • 2020-03-03
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    相关资源
    最近更新 更多