[eluser]nlweb[/eluser]
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
-application
-img <---- where the images are stored.
-css
-system
The gallery_model code is as follows:
Code:
class Gallery_model extends CI_Model{
var $gallery_path;
var $gallery_path_url;
function __construct(){
parent::__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);
$this->upload->do_upload();
$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);
$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_url . '/'. $file,
'thumb_url' => $this->gallery_path_url . '/thumbs/' . $file
);
}
return $images;
}
}
and the gallery view code as follows:
Code:
<div id="gallery">
<?php if(isset($images) && count($images)):
foreach($images as $image): ?>
<div class="thumb">
<a href="<?php echo $image['url'];?>">
<img src="<?php echo $image['thumb_url']; ?>"/>
</a>
</div>
<?php endforeach; else: ?>
<div id="blank_gallery">Please Upload an Image</div>
<?php endif; ?>
</div>
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.
Code:
class Gallery extends CI_Controller {
public function index()
{
$this->load->model('gallery_model');
if($this->input->post('upload')) {
// Received an upload
$this->gallery_model->do_upload();
}
$data['images'] = $this->gallery_model->get_images();
$data['main_content'] = 'gallery';
$this->load->view('includes/template', $data);
}
}