Codeigniter File Paths

15,934

Solution 1

You can use base_url function. To use this function you have to load url helper

You can load wherever it required as below:

$this->load->helper('url');

Or you can set in autoload.php.

echo base_url("resources/img001/img_name.jpg");
echo base_url("resources/style.css");

Solution 2

echo FCPATH."resources/img001/img_name.jpg";
echo FCPATH."resources/style.css";

Constant FCPATH will return system's path to Your front controller's file (index.php at root of Your CI-App)

Share:
15,934
TotalNewbie
Author by

TotalNewbie

Updated on June 14, 2022

Comments

  • TotalNewbie
    TotalNewbie almost 2 years

    sorry to bother but I am having some confusion with filepaths within codeigniter, as you may or may not know CI lays out its file system as follows:

    -application:
                 -controllers
                 -views
                 -models
    -system(contains CI framework)
    

    I have created a css file and have some images saved in the a resources folder like so:

     -application:
                 -controllers
                 -views
                 -models
    -system(contains CI framework)
    
    -resources
         -img001
         -style.css
    

    I was wondering whether someone could point me in the right direction to accessing the resources folder using relative paths.