douzhi4991 2013-08-02 19:15
浏览 9
已采纳

从目录读取的Codeigniter失败

I changed and now it does not show nothing. The directories exist on the folder.

i am giving you an example. If i echo $dir i get fullurlpath/root_folder/username

the whole path and directories exist so the $dir is ok, something else must happend.

class Front_Page extends CI_Model{

function front_display(){

    $this->db->select('id, username');
    $query = $this->db->get('models')->result();

    $display_models = '<ul class="display-models">';

    foreach ($query as $row){


        $username= $row->username;

        $dir = base_url('/img/'.$username.'');
        echo $dir;
        if(is_dir($dir)){
            if($dh = opendir($dir)){
                while(($file = readdir($dh)) !== FALSE){            

                    $display_models .= '<li>';
                    $display_models .= '<a href="profilepage/'.$row->id.'">';
                    $display_models .= '<img src="'.$dir.'/'.$file.'">';
                    $display_models .= '</a>';
                    $display_models .= '</li>';

                }

                closedir($dh);
            }
        }
    }

        $display_models .= '</ul>';

        return $display_models;
}

}

  • 写回答

1条回答 默认 最新

  • douzi9744 2013-08-02 20:14
    关注

    The error you are getting is sayings the path is not found, it has to exists first. The second problem is that you are using the code the wrong way even when the path is fixed.

    // Open a known directory, and proceed to read its contents
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                $display_models .= '<li>';
        $display_models .= '<a href="profilepage/'.$row->id.'">';
        $display_models .= '<img src="'. $dir.'/'. $file.'">';
        $display_models .= '</a>';
        $display_models .= '</li>';
            }
            closedir($dh);
        }
    }
    

    You will want something similar to the above, that is how you use that function.

    Remember that the path needs to be fixed first otherwise this will not loop through anything because the folder was not found and it will not find any files to loop through.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制