Jc John Jc John - 20 days ago 4x
PHP Question

how can i check the value of a variable from a controller in codeigniter

I am doing an upload image file in CodeIgniter. I want to trace out the image in my code and update my database path with it. I want to print the

variable in the code below where it was located in my controller.

How can I print the
variable to display or check its value inside the controller or maybe echo it out ?

Here it is:

public function upload_file()
$status = "";
$msg = "";
$file_element_name = 'userfile';

if ($status != "error") {
$config['upload_path'] = './assets/upimages/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1024 * 8;
$config['encrypt_name'] = FALSE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload($file_element_name))
$status = 'error';
$msg = $this->upload->display_errors('', '');
$data = $this->upload->data();
$image_path = $data['full_path'];
$status = "success";
$msg = "File successfully uploaded";
$status = "error";
$msg = "Something went wrong when saving the file, please try again.";
echo json_encode(array('status' => $status, 'msg' => $msg));


If I understand the question your asking then you want to view the contents of the $image_path variable.

If all you want is to check this then you could pass it back to the view with the json array ('image_path' => $image_path).

The other option is to var_dump($image_path) however to view this you would need to inspect the post data response on the browser and it may also stop the json from working while you are using the var_dump().