CodeIgniter Forums
Problem in uploading image - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Problem in uploading image (/thread-41653.html)



Problem in uploading image - El Forum - 05-13-2011

[eluser]raiser[/eluser]
Dear Friends,

I tried to upload image.. But couldn't do it.. I followed the user guide to upload. But somewhere i did some mistake. I cannot find it.. Kindly help me.. My code is,

View:

Code:
<?php echo form_open_multipart(''); ?>

<table width="866" height="100%" border="1" align="center" cellpadding="0" cellspacing="0" style="border:3px solid #FFFFFF;">
   <tr>
       <td width="23%" height="40" class="list_conents">Upload Image </td>
       <td width="5%" height="40" class="list_conents">:</td>
       <td width="72%" height="40">&lt;input type="file" name="page_img" id="page_img" size="40" class="browse_file"/&gt;&lt;/td>
  </tr>
   <tr>
        <td height="39">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&lt;input type="submit" name="submit" value="Submit" class="submit2"&gt;&nbsp;&lt;input type="reset" value="Reset" class="submit2" /&gt;&lt;/td>
    </tr>
</table>

Controller:

Code:
class Events_awards extends CI_Controller{
  public function _construct()
  {
    parents::_construct();
  }
  function index()
  {
        $config['upload_path']      =    './assets/images/news_events/';
        $config['allowed_types']    =    'gif|jpg|png';
        $config['max_size']         =    '0';
        $config['max_width']        =    '0';
        $config['max_height']       =    '0';
            
        $this->load->library('upload', $config);
        redirect('events_awards/add_event');
  }
}



Problem in uploading image - El Forum - 05-13-2011

[eluser]Alur[/eluser]
Hello raiser,

to begin with, in your view the form should point to the controller:

Code:
form_open_multipart('events_awards/index')


hope it helps!


Problem in uploading image - El Forum - 05-13-2011

[eluser]d1a8lo24[/eluser]
You're missing the following function

Code:
$this->upload->do_upload()

Also since you're using a different name on your file field you must specified that.

Code:
$this->upload->do_upload('somefieldname')

You can also reference the users guide again

http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

All the information is there.


Problem in uploading image - El Forum - 05-13-2011

[eluser]d1a8lo24[/eluser]
By the way as long as you're using the latest CI version you don't need to specify the uri or controller if it is being submitted to it self.


Problem in uploading image - El Forum - 05-16-2011

[eluser]raiser[/eluser]
Thanks d1a8lo24 for replying me.. I added
Code:
$this->upload->do_upload();
.. But still i cant get it.. Can you explain bit more?


Problem in uploading image - El Forum - 05-16-2011

[eluser]d1a8lo24[/eluser]
see the following example with your code

Code:
class Events_awards extends CI_Controller{
  public function _construct()
  {
    parents::_construct();
  }
  function index()
  {
        $config['upload_path']      =    './assets/images/news_events/';
        $config['allowed_types']    =    'gif|jpg|png';
        $config['max_size']         =    '0';
        $config['max_width']        =    '0';
        $config['max_height']       =    '0';
            
        $this->load->library('upload', $config);

        // since your file field name is called page_img just add the following line here.
        if ( ! $this->upload->do_upload('page_img'))
    {
            $error = array('error' => $this->upload->display_errors());

        $this->load->view('upload_form', $error);
    }
    else
        {

                redirect('events_awards/add_event');
        }
  }
}



Problem in uploading image - El Forum - 05-16-2011

[eluser]raiser[/eluser]
Thank you very much d1a8lo24.. Now it is working.. A big thanks


Problem in uploading image - El Forum - 05-16-2011

[eluser]d1a8lo24[/eluser]
No problemo