如何在codeigniter中显示现有的用户图片?

wmtdaxz3  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(299)

我有一个完整的php脚本,我从codecanyon买的,作者不支持costum工作。。。它是由codeigniter框架和它的工作良好和完美,但脚本不支持
用户上传配置文件图像的能力
上传图像的能力将显示在个人资料页。3重新加载或删除图像的能力。。。。。
我在谷歌上搜索了一下,却找不到答案。
我试过创建>上传控制器>上传视图>上传模型,它只上传到特定url中的指定文件夹,例如site.com/uploadimage。
我想问一下,是否有任何方法将此功能集成到系统中。。。我是个php新手。很多人提前感谢。。。

ou6hu8tu

ou6hu8tu1#

我希望这能帮助你。
创建此文件夹路径以上载图像:app\u data/images/account/

// Your Controller
Class User extends CI_Controller
{
    // This upload method
    function upload_user_photo()
    {
        $path  = 'app_data/images/account/';
        if(!file_exists($path))
        {
            mkdir($path, 0777, true);
        }

        $file_name                  = increment_string('image_profile', '-'); //use codeigniter string helper
        $config['upload_path']      = $path;
        $config['file_name']        = $file_name;
        $config['allowed_types']    = 'gif|jpg|png';
        $config['max_size']         = '100';
        $config['max_width']        = '1024';
        $config['max_height']       = '768';
        $this->load->library('upload', $config); 

        //Take an action if photo has been uploaded
        if($this->upload->do_upload('image'))
        {
            $upload_data = $this->upload->data();

            // View response from upload data
            echo "<pre>";
            print_r ($upload_data);
            echo "</pre>";

            // Array key is column name of your table
            $data = 
            [
                'user_id' => 'insert our user id',
                'photo' => $upload_data['file_name']
            ];

            //Take action save to your model
            $this->load->model('your_model_name');

            $this->your_model_name->save_profile_image($data);
        }
    }
}

# Model

Class Your_model_name extends CI_Model
{
    function save_profile_image($data)
    {
        $this->db->insert($data);
    }
}

阅读有关codeigniter上载设置首选项的更多信息

相关问题