Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Why this is not uploading?
#1

[eluser]solid9[/eluser]
Okay below is my form,
Code:
<?php
  echo '<br>';
  echo form_open_multipart('main/process_post');
?&gt;
  <div id="register" align="center">
  <table width="550" bgcolor="#333333">
  <tr>
   <td align="left">Offering</td>
   <td align="left">
    &lt;?php
    //[swapid] => 14
       //[date_posted] => 2012-03-10
       //[offering] => eight
       //[seeking] => 8    

    if(!empty($swap->swapid)) {
     $offer = $swap->offering;
     echo form_hidden('swap_id', $swap->swapid);    
    } else {
     $offer = '';
    }
    $data_form = array(
                  'name'        => 'offering',
                  'id'          => 'offering',
                  'value'       => $offer,
                  'rows'     => '15',
                  'cols'        => '55',
                );
        
    echo form_textarea($data_form);    
    ?&gt;
   </td>
  </tr>
  <tr>
   <td align="left">Seeking</td>
   <td align="left">
    &lt;?php  
    if(!empty($swap->swapid)) {
     $seek = $swap->seeking;
    } else {
     $seek = '';
    }
    $data_form = array(
                  'name'        => 'seeking',
                  'id'          => 'seeking',
                  'value'       => $seek,
                  'rows'     => '15',
                  'cols'        => '55',
                );

    echo form_textarea($data_form);    
    ?&gt;
   </td>
  </tr>
  <tr>
   <td align="left"> </td>
   <td align="left">
    <b>Upload photo(s)</b> &nbsp;&nbsp; <br>
     &lt;input type="file" name="userfile1" size="20" /&gt;&lt;br>
     &lt;input type="file" name="userfile2" size="20" /&gt;&lt;br>
     &lt;input type="file" name="userfile3" size="20" /&gt;&lt;br>
     &lt;input type="file" name="userfile4" size="20" /&gt;&lt;br>
     &lt;input type="file" name="userfile5" size="20" /&gt;&lt;br><br>
    &lt;?php echo form_submit('mysubmit', 'Publish'); ?&gt;</td>
  </div>
  </table>
&lt;?php
  echo form_close();
?&gt;


Below is my controller, (method only)
Code:
function process_post() {
  //get segment(3)
  $swap_id = $this->input->post('swap_id');
  $img1 = $this->input->post('userfile1');
  $img2 = $this->input->post('userfile2');
  $img3 = $this->input->post('userfile3');
  $img4 = $this->input->post('userfile4');
  $img5 = $this->input->post('userfile5');
  
  //validate data input first
  $this->form_validation->set_rules('seeking', 'seeking', 'required');
  $this->form_validation->set_rules('offering', 'offering', 'required');

  //if validation has an error display form again.
  if ($this->form_validation->run() == FALSE)
   {
    //Refresh the page and display error message
    $username = $this->session->userdata('username');
    $this->data['header_message'] = 'Please fill-up seeking and offering fields.';    
       $this->data['header'] = $this->load->view('header', $this->data, TRUE);
    $this->data['member_menu'] = $this->load->view('member_menu', null, TRUE);
    $this->data['midnav'] = $this->load->view('post_page', $this->data, TRUE);
       $this->load->view('front_page', $this->data);  
  } elseif(empty($swap_id)) {
    //Save to swap table, update users_swap table
    //This is for new records
    $offer = $this->input->post('offering');
    $seek = $this->input->post('seeking');
    $this->bs_model->publish_post($offer, $seek);
    
    //process image upload
    $config['upload_path'] = './photo-product/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '10000';
    $config['max_width']  = '500';
    $config['max_height']  = '500';
    $this->load->library('upload', $config);  
    
    //$this->upload->initialize($config);
    $this->upload->do_upload($img1);
    $this->upload->do_upload($img2);
    $this->upload->do_upload($img3);
    $this->upload->do_upload($img4);
    $this->upload->do_upload($img5);      
    
    //display view page
    $username = $this->session->userdata('username');
    $this->data['header_message'] = 'Your post is successfully published!';    
       $this->data['header'] = $this->load->view('header', $this->data, TRUE);
    $this->data['member_menu'] = $this->load->view('member_menu', null, TRUE);
    $this->data['midnav'] = $this->load->view('post_page', $this->data, TRUE);
       $this->load->view('front_page', $this->data);
  
  } elseif(!empty($swap_id)) {
    //update table
    //This is for existing record for updating
    $offer = $this->input->post('offering');
    $seek = $this->input->post('seeking');
    $this->bs_model->update_post($swap_id, $offer, $seek);

    $this->data['header_message'] = 'Your post is successfully updated!';    
       $this->data['header'] = $this->load->view('header', $this->data, TRUE);
    $this->data['member_menu'] = $this->load->view('member_menu', null, TRUE);
    $this->data['midnav'] = $this->load->view('post_page', $this->data, TRUE);
       $this->load->view('front_page', $this->data);
  }
}


Thanks in advanced.


#2

[eluser]solid9[/eluser]
I changed the following codes below,

from this,
Code:
$img1 = $this->input->post('userfile1');
  $img2 = $this->input->post('userfile2');
  $img3 = $this->input->post('userfile3');
  $img4 = $this->input->post('userfile4');
  $img5 = $this->input->post('userfile5');

to this,
Code:
$img1 = 'userfile1';
  $img2 = 'userfile2';
  $img3 = 'userfile3';
  $img4 = 'userfile4';
  $img5 = 'userfile5';


PROBLEM SOLVED!






Theme © iAndrew 2016 - Forum software by © MyBB