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 mysql , 用自己创建的本地主机和用户名 登录不上
  • ¥15 关于#web项目#的问题,请各位专家解答!
  • ¥15 vmtools环境不正常
  • ¥15 请问如何在Ubuntu系统中安装使用microsoft R open?
  • ¥15 jupyter notebook
  • ¥30 informer时间序列预测
  • ¥20 SSR引物多态性分析
  • ¥15 大漠插件在Win11易语言注册调用和免注册灵异事件,VS上注册调用完全没问题
  • ¥15 Addressable缓存机制做热更新的问题
  • ¥15 微信开发者工具vant组件