• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Array duplicating values?

#1
[eluser]solid9[/eluser]
Hi guys

I created an array below,
Code:
$filenames = array(
    '0' => '',
    '1' => '',
    '2' => '',
    '3' => '',
    '4' => '',
);

Everytime I fill-up the array with filenames value it generate this output below,
the 'u' won't go away and the last file names duplicate and fill-up the remaining empty
index of the array.
Code:
Array
(
    [0] => android15.jpg
    [1] => as315.jpg
    [2] => as315.jpg
    [3] => as315.jpg
    [4] => u
)

Why is this?

Thanks in advanced.

#2
[eluser]solid9[/eluser]
By the way the value of the array are filenames,
coming from the file_upload form.




#3
[eluser]solid9[/eluser]
okay to make it clear this is the 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;

and this the method
Code:
function process_post() {
  //get segment(3)
  $swap_id = $this->input->post('swap_id');
  $img1 = 'userfile1';
  $img2 = 'userfile2';
  $img3 = 'userfile3';
  $img4 = 'userfile4';      
  $img5 = 'userfile5';
  
  $file1 = '';
  $file2 = '';  
  $file3 = '';  
  $file4 = '';
  $file5 = '';    
  
  //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');
    $prodid = $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);
     $img1 = $this->upload->data($img1);
     //if(isset($userfile1)) {
      $file1 = $img1['file_name'];
  
    $this->upload->do_upload($img2);
     $img2 = $this->upload->data($img2);
      $file2 = $img2['file_name'];

    $this->upload->do_upload($img3);
     $img3 = $this->upload->data($img3);

      $file3 = $img3['file_name'];

    $this->upload->do_upload($img4);
     $img4 = $this->upload->data($img4);

      $file4 = $img4['file_name'];
    
    $this->upload->do_upload($img5);  
     $img5 = $this->upload->data($img5);

      $file5 = $img5['file_name'];
     //}
    
    echo "<pre>";
    echo '<br>', $file1;
    echo '<br>', $file2;
    echo '<br>', $file3;
    echo '<br>', $file4;
    echo '<br>', $file5;
    echo "</pre>";
    
    //save filename to sphoto table
    //$this->bs_model->save_product_photo($prodid, $file1, $file2, $file3, $file4, $file5);
    
    //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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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