Welcome Guest, Not a member yet? Register   Sign In
Problem in uploading image
#1

[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?
#2

[eluser]silent_assassin[/eluser]
any ideas?
#3

[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.
#4

[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.
#5

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




Theme © iAndrew 2016 - Forum software by © MyBB