[eluser]Antonius Willson[/eluser]
[quote author="AoiKage" date="1298992576"]There are threee ways to solve your problem:
1) In your controller, before you load the view, insert this line
Code:
$this->load->helper('form');
2) Autoload the helper in your application/config/autoload.php file. Search fo this (it may be different if you already autoload something):
Code:
$autoload['helper'] = array();
and add the form helper so it becomes like this:
Code:
$autoload['helper'] = array('form');
3) Just rewrite the whole form using plain old html

[/quote]
that's not work..
the problem is, why when i upload image that success..
but the image display can't be resize to be 150px x 50px..
i think you must, copy and try my code in your computer.
maybe you can help me.
thanks before.
controller code gallery.php :
Code:
<?php
class Gallery extends CI_Controller {
function index() {
//load Gallery_model.php from folder model
$this->load->helper('form');
$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', $data);
}
}
this is view code gallery.php :
Code:
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<title>CI Gallery</title>
<meta charset="UTF-8">
<style type="text/css">
#gallery, #upload {
border: 1px solid #ccc; margin: 10px auto; width: 570px; padding: 10px;
}
#blank_gallery {
font-family: Arial; font-size: 18px; font-weight: bold;
text-align: center;
}
.thumb {
float: left; width: 150px; height: 100px; padding: 10px; margin: 10px; background-color: #ddd;
}
.thumb:hover {
outline: 1px solid #999;
}
img {
border: 0;
}
#gallery:after {
content: "."; visibility: hidden; display: block; clear: both; height: 0; font-size: 0;
}
</style>
</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 src="<?php echo base_url().$image['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>
</body>
</html>
this is model code gallery_model.php
Code:
<?php
class Gallery_model extends CI_Model {
var $gallery_path;
var $gallery_path_url;
function __construct() {
parent::__construct();
$this->gallery_path = (APPPATH . '../images');
$this->gallery_path_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_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;
}
}
the last autoload.php, i change the helper become like this :
Code:
$autoload['helper'] = array('url','form','file');