【问题标题】:Image not displayed in codeigniter while displaying image?显示图像时图像未显示在codeigniter中?
【发布时间】:2015-10-30 09:09:35
【问题描述】:

我已在我的数据库中成功上传了一个带有图像名称的图像路径。但是当涉及到显示时,它不起作用。我已经在我的数据库中提交了个人资料。我不知道我要去哪里,错误请帮忙排序。

// Controller

    public function index() {
            if($this->session->userdata('is_login')) {
            $this->load->model('Display_profilepic');
            $data = $this->Display_profilepic->getImage();
            print_r($data);//nothing printed
            $data=array('profile_picture'=>$img);
            $this->load->view("my_profile",$data);



            }

// model Display_profilepic

    function getImage(){
    $id = $this->session->userdata('user_id');
    $this->db->select("*");
    $this->db->from('tbl_usrs');
    $this->db->where('user_id', $id);
    $query = $this->db->get();
    if($query->num_rows()==0)
    echo("Picture not found!");
    else{
    $data = $query->row_array();
    return $data['profile_picture'];
    print_r($data['profile_picture']);//nothing printed

我有一个单独的控制器和模型,用于将图像插入到定义路径的数据库中。让我知道我是否也应该发布它。

【问题讨论】:

  • print_r函数前有return语句。此外,不需要 else 语句末尾的 { (并且应该会导致错误)。
  • 当我在浏览器上看到页面源时“" 显示
  • 尝试将您的视图替换为 ">
  • 表中的profile_picture 是什么??
  • @Optimmus 你可以打印 $data 和 $query->num_rows() 并检查输出

标签: php image codeigniter


【解决方案1】:

试试这个代码:)

型号:

    function getImage()
    {
        $id = $this->session->userdata('user_id');
        $this->db->where('user_id',$id);
        $r=$this->db->get('tbl_usrs');
        if($r->num_rows()>0)
        {
            foreach ($r -> result_array() as $row) {
            $data[] = $row;
            }
        }
        $r->free_result();
        return $data;
    }

确保您的 $id 不为空。所以检查一次。

【讨论】:

  • 我在模型中得到未定义的变量 $data,在控制器中得到 $img
  • 上述问题你解决了吗?未定义的 $data 和 $img ?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-27
  • 2015-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多