douyao2529 2016-10-04 06:42
浏览 38
已采纳

如何从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 $image_path variable in the code below where it was located in my controller.

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

Here it is:

<?php
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('', '');
                }
                else
                {
                        $data = $this->upload->data();
                        $image_path = $data['full_path'];
                        if(file_exists($image_path))
                        {
                                $status = "success";
                                $msg = "File successfully uploaded";
                        }
                        else
                        {
                                $status = "error";
                                $msg = "Something went wrong when saving the file, please try again.";
                        }
                }
                @unlink($_FILES[$file_element_name]);
        }
        echo json_encode(array('status' => $status, 'msg' => $msg));
}
?>
  • 写回答

2条回答 默认 最新

  • donglun2010 2016-10-04 07:18
    关注

    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().

    Blinky

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程