Welcome Guest, Not a member yet? Register   Sign In
Some else can help me in this error message, then my problem i cannot view the images...
#1

[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">
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;CI Gallery&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
<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="&lt;?php echo $image['thumb_url']; ?&gt;" />
</a>
</div>
&lt;?php
}

} else {
?&gt;
<div id="blank_gallery">Please Upload an Image</div>
&lt;?php
}
?&gt;
</div>

<div id="upload">
&lt;?php
echo form_open_multipart('gallery');
echo form_upload('userfile');
echo form_submit('upload', 'Upload');
echo form_close();
?&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]InsiteFX[/eluser]
If you want help please wrap your code in code tags no one wants to try and read that.
#3

[eluser]Clooner[/eluser]
The error says the exact line of code you have to look at. You are trying to pass an array into a function which is expecting a string. Also it are notices that might not even interfere with the workings once you disable the display of them.

Also wrap your code next time!




Theme © iAndrew 2016 - Forum software by © MyBB