CodeIgniter Forums
Problem in uploading image - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Problem in uploading image (/showthread.php?tid=32363)



Problem in uploading image - El Forum - 07-21-2010

[eluser]silent_assassin[/eluser]
I m trying to write a simple program that uploads an image to a directory.when i press submit button i get following error message.
Quote:Fatal error: Call to undefined method CI_Upload::insert() in C:\wamp\www\code\system\application\models\post_data.php on line 11
This is my model
Code:
<?php
class Post_data extends Model
{
    function insert()
    {
    $config=array('upload_path'=>'./uploads/',
                       'allowed_types'=>'png|gif|JPG|JPEG|PNG|GIF',
                       'max_size'=>'1000');
    $this->load->library('upload',$config);
    $this->upload->insert();        
    }
  
}
?>
This is my controller
Code:
<?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();        
    }
    
    function index()
    {
            $this->load->model('post_data');
            $this->load->view('post_view.html');
        
            if($this->input->post('create_product'))
            {
                
                $this->post_data->insert();
            }
            
    }
}
and finally my view
Code:
<html>
    <head></head>
    <body>

<?php $this->load->helper('form'); ?>
<?php  echo form_open_multipart('Welcome'); ?>

   <?php echo form_upload();?>

    <p>
        &lt;?php echo form_submit('create_product', 'Upload image'); ?&gt;
        
    </p>
  
&lt;?php echo form_close(); ?&gt;
    &lt;/body&gt;
&lt;/html&gt;
How to overcome this error?


Problem in uploading image - El Forum - 07-21-2010

[eluser]silent_assassin[/eluser]
any ideas?


Problem in uploading image - El Forum - 07-21-2010

[eluser]mddd[/eluser]
In your model you say : $this->upload->insert();
But there is no 'insert' method in the upload class. Perhaps you meant : $this->upload->do_upload(); ??
Seems simple to me, if you just read the line of your code that is mentioned in the error message.


Problem in uploading image - El Forum - 07-21-2010

[eluser]silent_assassin[/eluser]
Thanks for your help.I changed the method.Program runs without any errors.But $this->upload->data() returns an empty array and image is not uploaded.


Problem in uploading image - El Forum - 07-21-2010

[eluser]mddd[/eluser]
Could be many things. Look at the errors to see what is wrong: $this->upload->display_errors();