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条)

报告相同问题?

悬赏问题

  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来