• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem in uploading image

#1
[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');
  }
}

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

#3
[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-gui...ading.html

All the information is there.

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

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

#6
[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');
        }
  }
}

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

#8
[eluser]d1a8lo24[/eluser]
No problemo


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.