2016-10-22 49 views
0

我正在tryng來調整用戶輪廓的圖像,但我有此錯誤:Laravel 5.2 - Intervation圖像調整

NotReadableException in Decoder.php line 96: Unable to init from given binary data.

我的控制器

public function updateAvatar(Request $request){ 

    if ($request->hasFile('image')) { 

     $user_id = Auth::user()->id . '.' . $request->file('image')->getClientOriginalExtension(); 

     // if i insert here: retur $user_id it return: 1.jpg it work well, 
     // my form work well, before i tryed to upload without resize and it work well. 
     // i want save image uploaded with id user and extention 
     // here i'm tryng to resize it, i installed intervation and inserted class 

     $img = Image::make('images/users',$user_id); 
     $img->resize(100, 100); 
     $img->save('images/users',$user_id);   
     $user = new User; 

     $user->where('email', '=', Auth::user()->email) 

       ->update(['image' => 'images/users/'.$user_id]); 
     return redirect('account')->with('message-success', 'Immagine profilo aggiornata con successo!'); 

    }else{ 
     return redirect('account')->with('message-error', 'File non trovato'); 
    } 
    } 

回答

0

你試圖提供兩個參數到Image::make(),但它應該只給一個。我想你可能想要做Image::make('images/users/'.$user_id)改爲?或者無論你的文件的完整路徑是什麼。

0

試試這個 - 我想你試圖從文本字符串創建一個圖像,或者可能是不存在的東西。我沒有我的代碼編輯器,所以我無法測試,讓我知道你得到了什麼?

public function updateAvatar(Request $request){ 

    if ($request->hasFile('image')) { 

     $user_id = Auth::user()->id . '.' . $request->file('image')->getClientOriginalExtension(); 

     $img = Image::make($request->file('image')); 
     $img->resize(100, 100); 
     $img->save('images/users',$user_id);   
     $user = new User; 

     $user->where('email', '=', Auth::user()->email) 
      ->update(['image' => 'images/users/'.$user_id]); 

     return redirect('account')->with('message-success', 'Immagine profilo aggiornata con successo!'); 

    } else{ 

     return redirect('account')->with('message-error', 'File non trovato'); 

    } 
} 
0
public function updateAvatar(Request $request){ 

    if ($request->hasFile('image')) { 

     $user_id = Auth::user()->id . '.' . $request->file('image')->getClientOriginalExtension(); 

     $base=base64_decode($request['image']); 
     $img = Image::make($base)->save($path); 
     $img->resize(100, 100); 
     $img->save('images/users',$user_id);   
     $user = new User; 

     $user->where('email', '=', Auth::user()->email) 
     ->update(['image' => 'images/users/'.$user_id]); 

     return redirect('account')->with('message-success', 'Immagine profilo aggiornata con successo!'); 

     } else{ 

      return redirect('account')->with('message-error', 'File non trovato'); 

     } 
} 

這肯定會解決你的問題..