Member Avatar

I want to store image path in database along with image name like /uploads/profilepic/name.jpg.
what happening is only path is beinged saved not image name like field in my table prfile_picture has updated /uploads/profilepic/
but i want image name also after trailing slash so that i can retrieve that image by name
plz help me out this.....


function upload()
        $session_data = $this->session->userdata('sessiondata');
        $user_id = $session_data['user_id'];
        //post image
        //set preferences
        $config['encrypt_name'] = TRUE; // for encrypting the name
        $config['upload_path'] = LARGEPATH;
        $config['allowed_types'] = 'jpg|png|gif';
        $config['max_size']    = '100000000';

        //load moadel ********
        //load upload class library
        $this->load->library('upload', $config);

        //$this->upload->do_upload('filename') will upload selected file to destiny folder
        if (!$this->upload->do_upload('filename'))
            // case - failure
            $upload_error = array('error' => $this->upload->display_errors());
            $this->load->view('edit_profile', $upload_error);
            // case - success
            //callback  returns an array of data related to the uploaded file like the file name, path, size etc
            $upload_data = $this->upload->data();
            //return $upload_data;
            // call to model function *********
            //$data['images'] = $this->Edit_profile->upload_image();
            $data['images'] = $this->Edit_profile->insert_new_post($img);

            $data['success_msg'] = '<div class="alert alert-success text-center">Your file <strong>' . $upload_data['file_name'] . '</strong> was successfully uploaded!</div>';
            $this->load->view('edit_profile', $data);


//model to insert

if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Edit_profile extends CI_Model {

      var $file_path;
      var $file_path_url;

     function __construct()
          // Call the Model constructor
          $this->file_path = realpath(APPPATH . '../upload/large');
          $this->file_path_url = base_url().'upload/large/';
          //$this->load->helper(array('form', 'url'));


        public function upload_image()  
        $files = scandir($this->file_path);
        $files = array_diff($files, array('.', '..', 'thumbs'));
        $images = array();
        foreach ($files as $file){
        $images [] = array(
          'url' => $this->file_path_url . $file,
          'thumb_url' => $this->file_path_url . 'thumbs/' .$file

        return $images;

         function insert_new_post($img)

        $session_data = $this->session->userdata('sessiondata');
        $user_id = $session_data['user_id'];

        $filePath = ltrim(LARGEPATH.$img['file_name'],'.');
        $query = "UPDATE `tbl_usrs` set profile_picture='".$filePath."' where user_id='".$user_id."'";
       // $this->db->query($query,array($img));
       $arg=array ($img);

                return true; // if added to database
            }else {
                    return false;



Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.