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

#1
[eluser]Unknown[/eluser]
Hi,

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.

http://net.tutsplus.com/tutorials/php/co...ipulation/


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

Model
______________________________________________________________________________

<?php
class Gallery_Model extends CI_Model
{
var $gallery_path;
var $gallery_path_2;

function Gallery_Model()
{
parent::__construct();
$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);
$this->upload->do_upload();
$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);
$this->image_lib->resize();
}

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

);
}
return $images;
}

}

__________________________________________________________________________________________
View
__________________________________________________________________________________________

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

</a>
&lt;?php endforeach; else: ?&gt;
<div id = "blank_gallery"> Please Upload an Image</div>
&lt;?php endif ?&gt;
</div>

<div class="grid_2 omega">
<div id = "upload">
&lt;?php
echo form_open_multipart('gallery');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();
?&gt;
</div>


___________________________________________________________________________________________
Controller
___________________________________________________________________________________________

&lt;?php
class gallery extends CI_Controller
{

function gallery()
{
parent::__construct();
$this->load->model("Gallery_Model");
}

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

}
$viewData['username'] =$this->session->userdata('UserName');
$data['images'] = $this->Gallery_Model->get_images();
$this->load->view('shared/header');
$this->load->view('gallery/gallerytitle');
$this->load->view('gallery/galleryview',$viewData,$data);
$this->load->view('shared/footer');

}
}







Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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