예제 #1
0
 public function postDel(Request $request, $img_id)
 {
     $res = ['response' => 'YES', 'status' => 0];
     $img = Img::findOrFail($img_id);
     if ($img->img_active == 0) {
         if (file_exists(public_path() . $img->img_hd)) {
             unlink(public_path() . $img->img_hd);
         }
         if (file_exists(public_path() . $img->img_big)) {
             unlink(public_path() . $img->img_big);
         }
         if (file_exists(public_path() . $img->img_small)) {
             unlink(public_path() . $img->img_small);
         }
         if (file_exists(public_path() . $img->img_tiny)) {
             unlink(public_path() . $img->img_tiny);
         }
         if (file_exists(public_path() . $img->img_square)) {
             unlink(public_path() . $img->img_square);
         }
         if (file_exists(public_path() . $img->img_uri)) {
             unlink(public_path() . $img->img_uri);
         }
         $p = !file_exists(public_path() . $img->img_hd) && !file_exists(public_path() . $img->img_big) && !file_exists(public_path() . $img->img_small) && !file_exists(public_path() . $img->img_tiny) && !file_exists(public_path() . $img->img_uri);
         if ($p) {
             $img->forceDelete();
             if (!Img::find($img_id)) {
                 $res['status'] = 1;
             } else {
                 $res['msgError'] = MSG_FA;
             }
         } else {
             $res['msgError'] = '出错了...';
         }
     } else {
         $res['msgError'] = '该图片正在被使用,请先删除相关关联,再试';
     }
     return response()->json($res);
 }