Welcome Guest, Not a member yet? Register   Sign In
Image Manipulation Problem
#1

[eluser]Antonius Willson[/eluser]
I got problem in image manipulation.

this is the error
Fatal error: Call to undefined function form_open_multipart() in C:\xampp\htdocs\CodeIgniter\application\views\gallery.php on line 44

this is code from 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;
    }
    
}

error in $images = array(); line 44

how to solve this problem.
thank you.
#2

[eluser]AoiKage[/eluser]
The problem is not the model, but the view gallery.php. It looks like you didn't load the form helper Smile
Try to autoload it from the autoload.php file in you config directory or load it manually in the controller.

If you don't want to load a new helper, just write the form opening tag using plain html.
#3

[eluser]Antonius Willson[/eluser]
[quote author="AoiKage" date="1298825441"]The problem is not the model, but the view gallery.php. It looks like you didn't load the form helper Smile
Try to autoload it from the autoload.php file in you config directory or load it manually in the controller.

If you don't want to load a new helper, just write the form opening tag using plain html.[/quote]

so, what must i do?

this is code for view gallery.php

Code:
<!DOCTYPE HTML>
&lt;html lang="en-US"&gt;
&lt;head&gt;
    &lt;title&gt;CI Gallery&lt;/title&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;style type="text/css"&gt;
        #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;
        }
    &lt;/style&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 src="&lt;?php echo base_url().$image['url']; ?&gt;" />
                </a>                
            </div>
        &lt;?php endforeach; else: ?&gt;
            <div id="blank_gallery">Please Upload an Image</div>
        &lt;?php endif; ?&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;
#4

[eluser]AoiKage[/eluser]
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 Smile
#5

[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 Smile[/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:
&lt;?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>
&lt;html lang="en-US"&gt;
&lt;head&gt;
    &lt;title&gt;CI Gallery&lt;/title&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;style type="text/css"&gt;
        #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;
        }
    &lt;/style&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 src="&lt;?php echo base_url().$image['url']; ?&gt;" />
                </a>                
            </div>
        &lt;?php endforeach; else: ?&gt;
            <div id="blank_gallery">Please Upload an Image</div>
        &lt;?php endif; ?&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;

this is model code gallery_model.php
Code:
&lt;?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');




Theme © iAndrew 2016 - Forum software by © MyBB