简体   繁体   中英

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;); ?>" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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