控制器調用
/** * [delimg 刪除單張圖片] * @return [type] [description] */ public function delimg(){ if (request()->isPost()) { $pic = input('request.pic'); //$pic為文件路徑 return delimg($pic); } }
公共方法
/** * [delimg 刪除文件] * @param [type] $pic [description] * @return [type] [description] */ function delimg($pic){ $path = __FILE__; $paths = substr($path,0,strpos($path,'application')); $pic1 = $paths."public" .DS . $pic; if(file_exists($pic1)){ @unlink($pic1); return true; } return false; }