데이터베이스에서 이미지를 삭제하고 이미지 저장소 인 폴더에서도 코드를 만들었지 만 "모두 체크"를 클릭하면 데이터베이스와 폴더에서 하나의 이미지 만 성공적으로 삭제됩니다. . 나는 무엇을 잘못 했는가? 여기 내보기가 사용 확인란 자바 스크립트 : 여기codeigniter를 사용하여 데이터베이스에서 여러 이미지 삭제
<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>
및
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');
}
만 하나 개의 이미지가 성공적으로 너무 폴더와 데이터베이스에서 삭제됩니다 내 컨트롤러
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;
echo "$file_name</br>";
$path_file = 'image/wallpaper/';
unlink($path_file.$file_photo);
}
$this->wallpaper_model->drop_photo($k);
redirect('admin/wallpaper','refresh');
}
}
내 모델입니다 , 그러나하려고하면 echo "$file_name</br>";
모든 이미지를 표시합니다. 나는 무엇을 잘못 했는가? 누구든지 나를 인도 할 수 있다면, 나는 그것을 감사 할 것이다.
당신이 전경을 쓸 수 있습니다 어디 형태의 작업은 그래서 난 당신에게 더 나은 아이디어를주고 내가 컨트롤러의 배열의 업데이트 기능을 추가 mustang83 –
@ 컨트롤러와 모델을 이해할 수 있고 보기에서 – user4419336
또한 삭제 기능에서 쿼리를 추가했습니다 – user4419336