[eluser]v1ctoria[/eluser]
Hello Everybody !
After having 2hours on it, I need your help for an image resize which is actually not working and I don't know why...
My controller
Code:
<?php
class Gallery extends CI_Controller {
function index() {
if ($this->input->post('upload')) {
$this->gallery_model->do_upload();
}
$data['images'] = $this->gallery_model->get_images();
$this->layouts->set_title('About');
$this->layouts->add_aside('login_form');
$this->layouts->view('gallery_view', $data);
}
}
My model
Code:
<?php
class Gallery_model extends CI_Model {
var $gallery_path;
var $gallery_path_url;
function __construct() {
parent::__construct();
$this->gallery_path = realpath(APPPATH . '../images');
$this->gallery_path_url = base_url().'images/';
}
function do_upload() {
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
'upload_path' => $this->gallery_path,
'max_size' => 2000
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
$data = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->gallery_path . '/thumbs/newimage.png',
'create_thumb' => TRUE,
'maintain_ration' => true,
'width' => 150,
'height' => 100
);
$this->load->library('image_lib', $data);
$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 just in case, this is my view is you want to test quickly :
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>
<div id="upload">
<?php
echo form_open_multipart('gallery');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();
?>
</div>
The upload is totally fine, but the resize is not working and I tried so many things to get it done, but no one worked.
Thank you all for your help