[eluser]Unknown[/eluser]
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: models/gallery_model.php
Line Number: 49
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: models/gallery_model.php
Line Number: 51
/**************************************************************************************/
Here my code
Controller Code
<?php
class Gallery extends CI_Controller {
function index() {
$this->load->model('Gallery_model');
if($this->input->post('upload')) {
$this->Gallery_model->do_upload();
}
$data['images'] = $this->Gallery_model->get_images();
$this->load->view('gallery');
}
}
/**************************************************************************************/
Model Code
<?php
class Gallery_model extends CI_Model {
var $gallery_path;
var $gallery_path_url;
function Gallery_model() {
//parent::CI_Model();
$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();
$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($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;
}
}
/**************************************************************************************/
View Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CI Gallery</title>
</head>
<body>
<div id="gallery">
<?php
if(isset($images) && count($images)) {
foreach($images as $image) {
?>
<div class="thumb">
<a href="<?php echo $image['url']; ?>">
<img="<?php echo $image['thumb_url']; ?>" />
</a>
</div>
<?php
}
} else {
?>
<div id="blank_gallery">Please Upload an Image</div>
<?php
}
?>
</div>
<div id="upload">
<?php
echo form_open_multipart('gallery');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();
?>
</div>
</body>
</html>