简体   繁体   English

在Codeigniter视图中显示根文件夹图像

[英]Display root folder image in Codeigniter view

i'm trying to display an image which is located at the root folder of my app, in the same level as the application folder, there is an uploads folder that holds the images. 我正在尝试显示位于应用程序根文件夹中的图像,与应用程序文件夹处于同一级别,有一个用于保存图像的上载文件夹。 I tried many ways to get there, such as this one: 我尝试了多种方法到达那里,例如:

<?php foreach($result as $row): ?>

    <!-- Main Content -->
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-md-10 mx-auto">
                <div class="post-preview">

                    <h2 class="post-title">
                        <?php echo $row->title; ?>
                    </h2>
                    <h4 class="post-subtitle">
                        <?php echo $row->calling; ?>
                          <!-- for test pusposes<span>This is the session: //<?php //echo $_SESSION['post_id']; ?></span> -->
                    </h4>

                </a>
                <br />
                <img style="width:100%;" class="img-responsive" src="http://localhost:8888/FintechBlog/uploads/<?php echo $row->img_path; ?>"/>
                <p class="post-meta">
                    <!-- <a href="#">Start Bootstrap</a> -->
                    <p><small>By <?php echo $row->username; ?> |
                        <?php echo time_elapsed_string($row->created); ?></small></p>
                        <p><?php echo $row->body; ?></p>
                    </div>
                    <hr>
                </div>
            </div>
        </div>

    <?php endforeach; ?>

Can someone give me some light? 有人可以给我一些光吗? Thank you!! 谢谢!!

You have to do like that 你必须那样做

Fist set base url 拳头设定基本网址

<base href="<?= site_url() ?>" />
<img src="uploads/imagename.png">

尝试base_url('uploads')它应该指向您想要的文件夹

用作

<img src="<?php echo site_url('uploads/'.$row->img_path;); ?>" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM