2 回答

TA貢獻1900條經(jīng)驗 獲得超5個贊
我解決了!我像這樣更改了控制器中的功能。
public function userLogout(Request $request)
{
$data = $request->all();
if ($request->isMethod('post')) {
if (preg_match('/^data:image\/(\w+);base64,/', $data['picture'])) {
$value = substr($data['picture'], strpos($data['picture'], ',') + 1);
$value = base64_decode($value);
$imageName = time() . '.png';
$val = Storage::disk('player-images')->put($imageName, $value);
$path = public_path('storage/player-images/'.$imageName);
Image::make($data['picture'])->resize(304, 277)->save($path);
$data['picture'] = 'player-images/' . $imageName;
User::where('name', Auth::user()->name)->update(['picture' => $data['picture']]);
}
}
return view('gallery');
}

TA貢獻1804條經(jīng)驗 獲得超7個贊
我知道您可能解決了您的疑問,但是我一直在尋找類似的東西但沒有找到,因此我將以下代碼留給可能需要它的人。此代碼的目標是使用 URL 從 Pixabay上的圖像。
我對類似問題的解決方案:
public function store(){
$url = json_decode(request('photo')); //Photo is the field that I fill in the view, that contain a URL to my image in pixabay;
$contents = file_get_contents($url);
$name = substr($url, strrpos($url, '/') + 1);
$blob = base64_encode($this->resizeImage($contents));
Photos::firstOrCreate(['photo' => $name,'thumb' => $blob]); //Photos is my model
}
private function resizeImage($contents) : string {
return (string) Image::make($contents)->resize(75, 75)->encode('data-url'); // Very important this cast to String, without it you can not save correctly the binary in your DB;
}
查看:為了在我的視圖中使用代碼:當我返回查看模型時,我使用“for”打印所有圖像,如下所示:
@foreach($photos as $element)
<img src="{{ base64_decode($element->thumb) }}" alt="" >
@endforeach
#Warning 非常重要,您的數(shù)據(jù)庫中有一個 Blob 字段,因此在 Laravel Migrate 的 Schema 中,您必須輸入以下內(nèi)容: $table->binary('thumb');
你可以在我的 git 上查看我的代碼:lucasfranson10/multisafepay
- 2 回答
- 0 關注
- 189 瀏覽
添加回答
舉報