在model里写个删除图片的方法:
public function delImage($where){
//取出原图文件名
$image = $this->where($where)->getField('image');
if(!$image) return ; //商品图片不存在时直接返回
$path = "./Public/Uploads/images/$image"; //准备路径
if(is_file($path)) unlink($path); //删除文件
}
Controller:
public function del(){
//接收参数
$id = I('get.id');
$model = D('partners');
$where = array('pid'=>$id);
//删除图片
$model->delImage($where);
//删除数据
$result = $model->where($where)->delete();
if($result){
$this->redirect('showList');
}else{
$this->error('删除失败!');
}
}