How to display uploaded photos in codeigniter

codeigniter registration form with image upload
image and video upload in codeigniter
image upload in codeigniter with database
file upload and download in codeigniter
how to display image in codeigniter from database
codeigniter image upload display
upload pdf file in codeigniter example
codeigniter rest api image upload

I am building a user profile in codeigniter. I have set up a system that allows the user to create a folder with their user-id, and then upload photos to it. I have been abel to successfully upload files to a folder but I am just not sure how to display the photo in my view pertinent to the user.

I would assume I attach it to my $user[''] just not sure exactly how to do that. Thanks in advance.

public function upload()
    {
        $this->load->library('session');
        $this->load->helper('url');
        $session_id = $this->session->userdata('id');
        $this->load->model('account_model');
        $user = $this->account_model->user();
        $data['user'] = $user;
        echo $user['id'];
        $user_folder = './uploads/' . $this->session->userdata('id');
        if(!is_dir($user_folder)){

            mkdir($user_folder, 0777);
        }
        $config['image_library'] = 'gd2';
        $config['source_image'] = $user_folder;
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['width']     = 50;
        $config['height']   = 50;

        $this->load->library('image_lib', $config); 

        $this->image_lib->resize();
        $config['upload_path'] = $user_folder;
        $config['allowed_types'] = 'gif|jpg|png';
        //$config['max_size']   = '165';
        $config['max_width']  = '165';
        $config['max_height']  = '165';

        $this->load->library('upload', $config);


        if ( ! $this->upload->do_upload())
        {

            $error = array('error' => $this->upload->display_errors());

            $data['main_content'] = '/account/upload';
            $this->load->view('includes/templates/main_page_template', $data);
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());

            $data['main_content'] = '/account/success';
            $this->load->view('includes/templates/main_page_template', $data);
        }
    }
    public function img(array $user=array()) {
        if(!isset($user['relation'])) {
            return '';
        }
        $path = '';
        if($user['relation'] != 'Choose One') {
            $path = '/styles/images/Sharpie' . $user['relation'] . '.gif';
        }
        return $path;
    }
}

Controller:

public function view_image($user_id)
{
     $this->load->model('account_model');

     $data['image'] = $this->account_model('model_that_will_fetch_relevant_image');

     $this->load->view('where_image_is',$data);

}

model:

public function get_image($user_id)
{ 

 $this->db->select('stuff'): \\ Select image filename

 $this ->db->where('table_that_has_user_id', $user_id ); 

 $query =  $this->db->get($this->_table_name . ' as aliase'); \\ where filename is

 return $query->result();
 }

view:

<img src = "<?=site_url('path/on/server/' . $image['image_filename']); ?>">

This assumes you are storing the image filename in a mysql database.

How to Upload Image & File in CodeIgniter (with Example), A Codeigniter file and image upload code is easy to integrate in any CI file upload component that could be easily used t upload images and other files with ease. To display the upload successful message, I will use the  The first folder is the destination folder that would receive the uploaded files. Next, go to the root of the CI installation and create a folder named “ uploads ”. Go to the view folder (located at the root of the CI installation) and create two new “view” files.

class Users_model extends CI_Model {

   var $table = 'tbl_admin';

   function __construct(){
       parent::__construct();
       $this->load->database();
   }

   public function processLogin($username,$password){ 
       $this->db->select('username,password');
       $where = $array = array('username' =>$username,'password'=>$password);
       $this->db->where($where);
       $this->db->from($this->table);
       $query = $this->db->get();
       return $query;
   }
}

How to Upload Image and File in CodeIgniter, This is so we can show error messages in the event the user does something wrong. You'll need a destination directory for your uploaded images. Create a  CodeIgniter File Upload - Upload multiple files and images in CodeIgniter. Example code to upload multiple images using Upload library in CodeIgniter, retrieve images from the database and display uploaded images in a gallery view. Use Upload Class to upload multiple images in CodeIgniter.

Please use this code, I hope it will help you.

Using profile_image variable you can display image.

<?php 

public function upload()
    {
        $this->load->library('session');
        $this->load->helper('url');
        $session_id = $this->session->userdata('id');
        $this->load->model('account_model');
        $user = $this->account_model->user();
        $data['user'] = $user;
        echo $user['id'];
        $user_folder = './uploads/' . $this->session->userdata('id');
        if(!is_dir($user_folder)){

            mkdir($user_folder, 0777);
        }
        $config['image_library'] = 'gd2';
        $config['source_image'] = $user_folder;
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['width']     = 50;
        $config['height']   = 50;

        $this->load->library('image_lib', $config); 

        $this->image_lib->resize();
        $config['upload_path'] = $user_folder;
        $config['allowed_types'] = 'gif|jpg|png';
        //$config['max_size']   = '165';
        $config['max_width']  = '165';
        $config['max_height']  = '165';

        $this->load->library('upload', $config);


        if ( ! $this->upload->do_upload())
        {

            $error = array('error' => $this->upload->display_errors());
            $data['main_content'] = '/account/upload';
            $this->load->view('includes/templates/main_page_template', $data);
        }
        else
        {
            $image = array('upload_data' => $this->upload->data());
            $data['profile_image'] = $user_folder.$image['upload_data']['file_name'];
            $data['main_content']  = '/account/success';
            $this->load->view('includes/templates/main_page_template', $data);
        }
    }
    public function img(array $user=array()) {
        if(!isset($user['relation'])) {
            return '';
        }
        $path = '';
        if($user['relation'] != 'Choose One') {
            $path = '/styles/images/Sharpie' . $user['relation'] . '.gif';
        }
        return $path;
    }
}

File Uploading Class, This is so we can show error messages in the event the user does something wrong. You'll need a destination folder for your uploaded images. Create a  So, Create a folder named “uploads” at the root of your CodeIgniter(CI) installation. Now create two “view” files file_view.php and upload_success.php in a views folder of CodeIgniter . First file will display a complete form that contains upload field and the second file is to display the message “successfully uploaded”.

File Uploading Class : CodeIgniter User Guide, CodeIgniter has upload library which makes easier to handle file In this tutorial, I show how you can upload multiple image files in CodeIgniter. send image from one page to display in another page ; image upload at server in image folder and path in database and display it on jsp ; Display record from database and update ; Two user fill the same form ; Trouble with Codeigniter + AR + Highcharts ; Cannot Retrieve Pdf From Mysql Using Fpdi In Php ; blueimp gallery question ; Drodown list insert

How to upload Multiple Files and Images in CodeIgniter, First file is to upload image and Second file is display Success message. Structure of "imageupload_form.php" this for uploading a image. <!DOCTYPE  The Process¶. Uploading a file involves the following general process: An upload form is displayed, allowing a user to select a file and upload it. When the form is submitted, the file is uploaded to the destination you specify. Along the way, the file is validated to make sure it is allowed to be uploaded based on the preferences you set.

Upload Multiple Images and Files in CodeIgniter, Whereas in the sidebar, I display a small image (140x68px). Multiple thumbnails are the result of uploading images of different sizes and  I want to upload the image to the mysql database for storing many information. I have attached the 3 (MVC) code for your reference and please help me.