CodeIgniter 将图像重命名为 db 表中的下一个 id



我是codeigniter的新手,正在尝试将我的图像重命名为表中的下一个自动递增数字。

我正在考虑使用

$id = $this->db->insert_id();

但是我仍然不确定如何将 1 添加到该值并将其用于我的文件名。 我已经设置了所有图像大小调整,只需要重命名,我就设置好了。

任何帮助将不胜感激!! 非常感谢!

控制器:

$config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $this->load->library('upload', $config);

        if ( !$this->upload->do_upload() )
        {
            $error = array('error' => $this->upload->display_errors());
            redirect('index.php/success');
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
            $this->resize($data['upload_data']['full_path'], $data['upload_data']['file_name']);
            redirect('index.php/success');
            echo $img;
        }
        // Update Record to save filename
    }
    function resize($path, $file){
        $config['image_library']= 'gd2';
        $config['source_image']= $path;
        $config['create_thumb']= TRUE;
        $config['maintain_ration']= TRUE;
        $config['width']= 320;
        $config['height']= 196;
        $config['new_image']='./uploads/'.$file;
        $this->load->library('image_lib', $config);
        $this->image_lib->resize();

    }

获取已设置为自动递增的 id 列的最后一个数字。你可以使用 sql Max() 函数来实现这一点。然后只需添加一个 1 并将其用于图像重命名。就是这样!!!

最新更新