Jump to content

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!

Edited by TFT2012
Link to comment
https://forums.phpfreaks.com/topic/291954-ci-image-path-help/
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.

Link to comment
https://forums.phpfreaks.com/topic/291954-ci-image-path-help/#findComment-1494763
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.