开发者

codeigniter image path

I am a codeignite newbie and tried to add an image in my file under view folder.

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

however, if I change my path to

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

I can see the image.

My file开发者_如何学JAVA system is as follow:

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 anyone help me about this? Thanks a lot!


I would suggest storing images in an images folder at the same level as the application folder, instead of trying to mix both PHP code and resources underneath application. Then just link to it like you did to the user guide:

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


I know more than year has passed since the question was asked but for anyone who comes looking in future, Here is my solution....

I've tried this created a folder images at same level as that of application, in main index.php added a line before last require_once statement.

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

and used IMAGE_PATH anywhere I wanted to display images.

Hope this helps


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

then on the views i just use /images


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

and put the images folder outside of the application folder in the same directory


Create an images folder at the same level of the applications folder.

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

This is useful because unlike site_url(), you can supply a string to a file, such as an image or stylesheet.
For example:

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

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

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


it is better practice to upload the images in a folder that is present in the root or the site folder and use base href in the first line of head tag. then the whole page does not need and http path reference. just use the relative path. as codeigniter run using the index.php file in the root, we should use all the relative path w.r.t that index.php page


on local server try this

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

on live use this

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


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

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


Your file structure should be -applications -images -assets -Or any folder. Keep the application folder, images folder, and assets folder inside the basic root folder.


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" />


<img src="<?php echo base_url('/assests/images/image_name.jpg')?>" alt="">

This is the exact path for codeigniter, don't need write the "../../.." just write the path from assets (folder name)(sibling of application). base_url gives the path of your project folder, not the path of the view folder inside application folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜