Welcome Guest, Not a member yet? Register   Sign In
base_url(), site_url(), nothing working to display images

I am following some tutorials on an image gallery, modifying the 1.7 code to fit the 2 code and everything has been working fine until I get to displaying any images on the page.

I have my directory tree as
-img <---- where the images are stored.

The gallery_model code is as follows:
class Gallery_model extends CI_Model{
var $gallery_path;
var $gallery_path_url;

function __construct(){
  $this->gallery_path = realpath(APPPATH . "../img");
  $this->gallery_path_url = base_url().'img';

function do_upload(){

  $config = array(
   'allowed_types' => 'jpg|jpeg|gif|png',
   'upload_path' => $this->gallery_path
  $this->load->library('upload', $config);

  $image_data = $this->upload->data();

  $config = array(
   'source_image' => $image_data['full_path'],
   'new_image' => $this->gallery_path . '/thumbs',
   'maintain_ratio' => true,
   'width' => 150,
   'height' => 100

  $this->load->library('image_lib', $config);

function get_images()
  $files = scandir($this->gallery_path);
  $files = array_diff($files, array('.', '..', 'thumbs'));

  $images = array();

  foreach($files as $file){
   $images[] = array(
    'url' => $this->gallery_path_url . '/'. $file,
    'thumb_url' => $this->gallery_path_url . '/thumbs/' . $file
  return $images;


and the gallery view code as follows:
<div id="gallery">
  &lt;?php if(isset($images) && count($images)):
   foreach($images as $image): ?&gt;
   <div class="thumb">
    <a href="&lt;?php echo $image['url'];?&gt;">
     <img src="&lt;?php echo $image['thumb_url']; ?&gt;"/>

  &lt;?php endforeach; else: ?&gt;
  <div id="blank_gallery">Please Upload an Image</div>
  &lt;?php endif; ?&gt;
I am using the .htaccess trick to get rid of the index.php, the correct site URL is loaded in config and index.php is removed from config as well.

The pictures correctly upload, (main image in the img folder and the thumbs go into the "thumbs" folder, but if I try to view them on a page, or even call them directly (localhost/dev/img/pic.jpg) it will say 404. The links ARE showing up correctly in the View Source. I have tried Base_url, site_url, and even created a custom "asset_url()" and nothing works.

Any help would be appreciated. I have googled this problem for the past few hours and I cannot find anything similar to this problem, or someone just posted "fixed it" and didnt reply how.

EDIT: Just in case you need to see the functions called, here is the controller. Pretty simple.
class Gallery extends CI_Controller {

public function index()
  if($this->input->post('upload')) {
   // Received an upload

  $data['images'] = $this->gallery_model->get_images();
  $data['main_content'] = 'gallery';
  $this->load->view('includes/template', $data);


Messages In This Thread
base_url(), site_url(), nothing working to display images - by El Forum - 05-27-2012, 03:48 PM

Theme © iAndrew 2016 - Forum software by © MyBB