2016-08-08 134 views
0

我想從數據庫中刪除記錄以及從server.I在控制器中的該記錄上傳的圖像。從服務器上刪除圖像

public function delete(Request $request) 
    { 
     if($request->ajax()) 
     { 
      $id=$request->get('id'); 
      if($id) 
      { 
       $delete=Category::where('id',$id)->first(); 
       $delete->delete(); 
       $imgfile='C:\xampp\htdocs\larapro\public\newuploads\<?php echo $delete->image;?>'; 
       unlink($imgfile); 
       echo json_encode(TRUE);die; 
      } 
     } 
     echo json_encode(FALSE);die; 
    } 

取消鏈接(C:\ XAMPP \ htdocs中\ larapro \ PUBLIC \ newuploads \ < PHP的echo $ 刪除 - >圖像;?>):結果太大

如果我使用

$imgfile="C:\xampp\htdocs\larapro\public\newuploads\{$delete->image}"; 

它顯示:

取消鏈接(C:MPP \ htdocs中\ larapro \ PUBLIC \ ewuploads {} 1470667358.png): 無效參數

,我只是想知道爲什麼x和N的鏈接丟失。

+0

那麼你到底有什麼問題呢? – PeterPan666

+0

圖片未被刪除。顯示結果太大@PeterPan666 – micky

+0

爲什麼你的PHP函數中有''塊? – apokryfos

回答

0

使用斜槓(/)而不是反斜槓():

$imgfile="C:/xampp/htdocs/larapro/public/newuploads/{$delete->image}"; 

或轉義轉義字符一樣,

$imgfile="C:\\xampp\htdocs\larapro\public\newuploads\{$delete->image}"; 

和X和n的缺失,因爲\ X \ n分別是轉義符和換行符。

1
public function delete(Request $request) 
     { 
      if($request->ajax()) 
      { 
       $id=$request->get('id'); 
       if($id) 
       { 
        $delete=Category::where('id',$id)->first(); 

        $imgfile="C:\xampp\htdocs\larapro\public\newuploads\$delete->image"; 
        //perform the delete after using the image/filename 
        $delete->delete(); 

        unlink($imgfile); 
        echo json_encode(TRUE);die; 
       } 
      } 
      echo json_encode(FALSE);die; 
     } 

你可以用你的單引號替換雙打,然後使用刪除變量的內容嗎?在這種情況下

+0

沒有幫助。 – micky

+1

你應該在'{$ delete-> image}'周圍使用花括號' – PeterPan666

相關問題