TFT2012 Posted October 20, 2014 Share Posted October 20, 2014 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! Link to comment https://forums.phpfreaks.com/topic/291954-ci-image-path-help/ Share on other sites More sharing options...
sKunKbad Posted October 25, 2014 Share Posted October 25, 2014 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.