Welcome Guest, Not a member yet? Register   Sign In
Multiple delete image from database and folder too
#1

hey dear i just curious that about multiple delete,

here is my view using check box javascript

Code:
<form name="indonesia" action="<?php echo site_url('admin/wallpaper/delete'); ?>" method="post">  
        
         <button type="submit" class="btn btn-danger" name="hapus" value="hapus">Hapus</button>

          <?php echo anchor('admin/wallpaper/tambah', 'Tambah Wallpaper');?>
          
        <table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
        <thead>
            <tr>
                 <th>
                    <button type="button" class="btn btn-info" onClick="check_all()" >Check</button>
                    <button type="button" class="btn btn-success" onClick="uncheck_all()" >Un-Check</button>
                </th>
                <th>id</th>
                <th>Keterangan</th>
                <th>Gambar</th>
                <th>Action</th>
            </tr>
        </thead>
        
            <tbody>
                <?php
                foreach ($ListWallpaper->result() as $row)
                {
                ?>
            <tr>
                <td><input type="checkbox" name="item[]" id="item[]" value="<?=$row->id_wall ?>"></td>
                <td><?=$row->id_wall ?></td>
                <td><?=$row->ket ?></td>
                <td><?=$row->wall ?></td>
                <td>
                    <a href="<?php echo base_url() ?>admin/wallpaper/hapus/<?= $row->id_wall ?>" class="label label-success">Delete</a>
                    
                    <a href="<?php echo base_url() ?>admin/wallpaper/edit/<?= $row->id_wall ?>" class="label label-success">Update</a>
               </td>
            </tr>
           <?php  }  ?>
        </tbody>
    </table>
          
    </form>

and here is my controller

Code:
public function delete()
    {
        
    $ownerNames = $this->input->post('item');

    foreach ($ownerNames as $ownerName => $k) {
    
     //echo "Array : " . $k . "<br/>";
    
    $photo = $this->wallpaper_model->del_photo($k);
    
    if ($photo->num_rows() > 0)
        {
            $row = $photo->row();
            $file_photo = $row->wall;
            $path_file = 'image/wallpaper/';
            unlink($path_file.$file_photo);
        }
        
      $this->wallpaper_model->drop_photo($k);
      
      redirect('admin/wallpaper','refresh');
    }
}

model
Code:
function del_photo($k)
                {
                    $this->db->where('id_wall',$k);
                    
                    $query = $getData = $this->db->get('tabel_wall');
                            
                            if($getData->num_rows() > 0)
                                    
                                return $query;
                            
                            else
                                  
                               return null;
                }

                                                    
function drop_photo($k)
                                {
                                    $this->db->where('id_wall',$k);
                                    
                                    $this->db->delete('tabel_wall');
                                }


i dont get some error just delete one image in folder when i clicked all, what do i wrong in my MVC, but when i print_r or echo it $file_photo = $row->wall; <--show the name_file ?

anyone suggest for me to fix it, gonna big appreciate that and help others if they face like me


Thanks
Reply


Messages In This Thread
Multiple delete image from database and folder too - by freddy - 02-04-2015, 10:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB