• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CodeIgniter from Scratch: Day 9 Tutorial Problems displaying images


I've been following the codeigniter from scratch tutorial on how to upload and display images and found them very worthwhile, however I have been having issues with the displaying images section of the tutorial. The files upload without issue to the correct folder but I cannot make them display. I believe the function getimages is not working correctly in my code but I'm not sure how to fix it.


Can anyone see where I am going wrong?

Any help is greatly appreciated!!

My config file looks as follows

$config['index_page'] = 'lab06_spacebook.php';

My .htaccess file is as follows

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ lab06_spacebook.php?/$1 [L]

Heres a copy of my code


class Gallery_Model extends CI_Model
var $gallery_path;
var $gallery_path_2;

function Gallery_Model()
$this->gallery_path=realpath(APPPATH .'../lab06_spacebook/assets');
$this->gallery_path_2=base_url() .'assets';

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_ration' =>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)
'url' =>$this->gallery_path_2 . $file,
'thumb_url' =>$this->gallery_path_2 .'thumbs/'. $file,

return $images;



<div class="container_12">
<div class="grid_7 prefix_3">
<div class="grid_2 alpha">
<h2> Photo Gallery </h2>
<div class="grid_3">
<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;

<div class="grid_2 omega">
<div id = "upload">
echo form_open_multipart('gallery');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();


class gallery extends CI_Controller

function gallery()

function index()
if ($this->input->post('upload')){

$viewData['username'] =$this->session->userdata('UserName');
$data['images'] = $this->Gallery_Model->get_images();


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.