Codeigniter image path

I am new to codegine and tried to add image to my file in view folder.

I am adding <img src="../images/myImage.jpg"></img> to my service_view.php. All I see is a broken link to a small icon.

however, if I change my path to

 <img src="../../user_guide/images/myImage.jpg"></img> 

I see the image.

My file system is as follows:

 application- view ->folder (where service_view.php is located) images -> folder (where myImage.jpg is located) user_guide- images ->folder ((where myImage.jpg is located)) 

Can someone help me with this? Many thanks!

+7
source share
10 answers

I suggest storing images in the images folder at the same level as the application folder, instead of trying to mix PHP code and resources under application . Then just connect to it, as you did with the user manual:

 <img src="../../images/myImage.jpg" /> 
+5
source

I know that more than a year has passed since the question was asked, but for those who come to the future, Here is my solution ....

I tried this by creating a folder image at the same level as the application, a line was added to the main index.php before the last require_once operation.

 define('IMAGE_PATH', APPPATH.'../images/'); 

and used IMAGE_PATH wherever I wanted to display images.

Hope this helps

+6
source

I just have an image folder, domain.com/images

then on representations i just use / images

+6
source
 <img src="<?php echo base_url(); ?>images/image.png" /> 

and put the image folder outside the application folder in the same directory

+3
source

Create a folder with images on the same level as the application folder.

With base_url() you can get the location of the site base (cfr config).

This is useful because, unlike site_url (), you can specify a string in a file, such as an image or style sheet.
For instance:

 <img src="<?php echo base_url("/images/icons/stackOverflow.png"); ?>" alt="StackOverflow" title="StackOverflow is the best!" /> 

This will give you something like: ... src="http://example.com/images/icons/stackOverflow.png" ...

Source: http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html

+3
source

it’s better to upload images to a folder that is present in the root or folder of the site, and use the href base link in the first line of the header. then the whole page is not needed and the link to the http path. just use the relative path. since codeigniter is launched using the index.php file in the root, we must use all relative wrt paths that the index.php page

0
source

on the local server try this

 <img src="http://localhost/ci/uploads/<?php echo $this->upload->data()['file_name'];?>" width="200px"/> 

in real time it

 <img src="<?php echo base_url();?>/uploads/<?php echo $this->upload->data()['file_name'];?>" width="200px"/> 
0
source

put the folder in the root directory, such as "assets / images /", and in your code just use it as

<img src="assets/images/imgname.jpg"></img>

0
source

Your file structure should be -applications -images -assets -or any folder. Store the application folder, image folder, and resource folder in the main root folder.

0
source

Use when you want to include something from your root folder

FCPATH = C: \ xampp \ htdocs \ your_root_folder \

 <img src="<?php echo FCPATH; ?>/images/myImage.jpg" /> 
0
source

Source: https://habr.com/ru/post/892955/


All Articles