无法将Codeigniter中的文件与文件链接超过10个文件

时间:2015-10-12 16:19:34

标签: php codeigniter

transform.LookAt(player);

当我尝试使用此代码时,请完成但不是全部删除,请帮助我

2 个答案:

答案 0 :(得分:0)

可能是path is the issue.try获取document root然后构造路径并使用路径unlink文件。

$path = $_SERVER['DOCUMENT_ROOT'].'/assets/pdf/data_napi/';
f($get_img){
        $img = array('pic1','pic2','pic3','pic4', 'pic5', 'pic6', 'pic7', 'pic8', 'pic9', 'pic10', 'pic11', 'pic12');
        foreach($img as $im){

    if($get_img[$im]){
                unlink($path.$get_img[$im]);
            }
  }
}

答案 1 :(得分:0)

好吧,在我看来,如果9被删除,它应该删除所有。您可以执行一些日志记录来查看要删除的文件。

所以

public function delete($id){
    $get_img  = $this->db->select('pic1, pic2,pic3,pic4,pic5, pic6,pic7, pic8, pic9, pic10, pic11, pic12')->where('id',$id)->get('napi')->row_array();
    //remove all images
    if($get_img){
        $img = array('pic1','pic2','pic3','pic4', 'pic5', 'pic6', 'pic7', 'pic8', 'pic9', 'pic10', 'pic11', 'pic12');
        foreach($img as $im){
            if($get_img[$im]){
                unlink('assets/pdf/data_napi/'.$get_img[$im]);
                echo '<p>assets/pdf/data_napi/'.$get_img[$im].'</p>'; // to display image that is deleted.
                $this->db->delete('napi',array('id'=>$id));//delete from db.
            }
        }
    }        
    //return $this->db->delete('napi',array('id'=>$id));
    /* as above line returns the control to it's master after deleting one record only.
       so you need to put this line inside loop*/
}