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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵