Jump to content

Archived

This topic is now archived and is closed to further replies.

TFT2012

CI Image Path Help

Recommended Posts

I have the folder structure like:

root

  • application
  • system
  • assets
  • uploads

folder assets contains all css, img, and js.

uploads contains user uploaded file.

 

I set a "helper/assets_helper.php" file to define:

define ('ASSETS_PATH', base_url().'assets/');
define ('UPLOAD_URL', base_url().'uploads/');

For all the css, img, and js, it works well like

href="<?php echo ASSETS_PATH; ?>css/mycss.css"

But when I display the uploaded images, it couldn't display image with

<a href="<?php echo UPLOAD_URL;?>images/myupload01.jpg" ><img src="<?php echo UPLOAD_URL;?>images/myupload01.jpg" /></a>

This uploaded image actually works fine with my localhost with the link like: http://localhost:9000/uploads/images/myupload01.jpg.

 

But it couldn't display on my hosting server with like: http://users.mywebsite.com/uploads/images/myupload01.jpg

 

Can anyone shed some light on it. Thanks!

Share this post


Link to post
Share on other sites

First, you have a constants config file for a reason. You shouldn't have to load a helper just to define a constant. Define your constants in config/constants.php.

 

Secondly, CI makes it easy for you to have constants.php files that match the environment. So for development you would have a file config/development/constants.php, and for production you would have config/production/constants.php.

 

Last, instead of wasting your energy always using your constants as you have shown above, why not just create a new or modified function in MY_html_helper.php? The HTML helper already has an img() function, so either tweak that one to use your constants, or create a new one. That way, all you do is call your function, which is a lot easier.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.