Jc John Jc John - 3 months ago 14
PHP Question

how can i get the working path of my image in codeigniter when uploading

I have a code in codeigniter which i will store the path of my image in my database. It works fine in inserting but the path is not correct.

My folder name of my upload images are stored in upimages.
The upimages is located in outside of application folder in codeigniter where i created assets/upimages. Here is my path code in inserting to database:

$data = $this->upload->data();

$image_path = $data['full_path'];
$userid = ($this->session->userdata['logged_in']['user_id']);
$imagedb = $this->prof_model->user_img($image_path,$userid);
if(file_exists($image_path)) {
$status = "success";
$msg = "File successfully uploaded";


my image_path is the full path of my image but it outputs none if i call it again and here is the output of the full_path in my database:

when i change the path in my db and change it to :
it works fine.

my question is. how can i adjust my full_path to come up with the 2nd path. Remember that the location of my upimages is outside of the application folder which i created an asset/upimages


Try to make your file path as like as following:

$image_url = base_url().'assets/upimages/'.$data['upload_data']['file_name'];
$imagedb = $this->prof_model->user_img($image_url,$userid);