• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
controlling and specification of loop items

#1
i am using codeigniter to replace files in directory and update location in database, i have multiple files so when i update them all it works good updates and replaces all of them, but when i update one, or more specific files it updates and replaces all those retrieved from the database. it operates on all of them.
the controller:

PHP Code:
public function upload()
 
   {
 
       $config ['upload_path'] = 'uploads';
 
       $config ['allowed_types'] = 'gif|jpg|png';
 
       $config ['encrypt_name'] = TRUE;
 
       $config['overwrite'] = TRUE;

 
       $this->upload->initialize($config);

 
       $files $_FILES;
 
       $cpt count($_FILES ['images'] ['name']);

 
       for ($i 0$i $cpt$i++) {
 
           echo $i '<br>';
 
           $image Image::find($_POST['images']['id'][$i]);
 
           //$query = Image::find('id');
 
           if(file_exists("./uploads/$image->image_location")) {
 
               unlink("./uploads/$image->image_location");
 
           }
 
           $_FILES ['images'] ['name'] = $files ['images'] ['name'] [$i];
 
           $_FILES ['images'] ['type'] = $files ['images'] ['type'] [$i];
 
           $_FILES ['images'] ['tmp_name'] = $files ['images'] ['tmp_name'] [$i];
 
           $_FILES ['images'] ['error'] = $files ['images'] ['error'] [$i];
 
           $_FILES ['images'] ['size'] = $files ['images'] ['size'] [$i];

 
           if ($this->upload->do_upload('images')) {
 
               $upload_data $this->upload->data();
 
               $file_name $upload_data['file_name'];
 
               $image->update_attributes(array('image_location' => $file_name));
 
           } else {
 
               $this->upload->display_errors();
 
               //echo "$error";
 
           }

 
       }

 
   }

the view:

 <
ul>
 
       <?php
        foreach
($image as $row)
 
       {?>
            <?= form_hidden('images[id][]'set_value('id', isset($row->id)?$row->id:''))?>

        <label><input type="file" name="images[]" ><?php echo $row->image_location?></label>
        <?php }?>
    </ul> 
Reply

#2
What is being posted to the server?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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