duandie5707 2018-04-16 21:17
浏览 54

如何在Codeigniter中显示现有用户图片。

I have a complete php script which i bought from codecanyon and the Author does not support costum work... it was made with Codeigniter framework and its working fine and perfectly but the script does not support

  1. Ability for User to Upload Profile Image
  2. Ability for uploaded image be shown in profile page. 3 Ability to ReUpload and or delete image.....

I have search google for it and could not find answers to this.

I have tried Creating >Upload-Controller > Upload View > Upload Model, which only upload to a specified folder in a specific url e.g site.com/uploadimage.

I want to ask if there is any way to integrate this feature to the system... Am a php newbie. Many Thank in Advance...

  • 写回答

1条回答 默认 最新

  • duandian4501 2018-04-17 06:29
    关注

    I hope this can help you.
    Create this folder path for uploading the image : app_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);
        }
    }
    

    Read more about codeigniter upload setting preferences

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看