我想使用Laravel上传用户图片。我将照片上传到存储文件夹,但没有显示在我的视觉视图页面上。如何更改照片的路径? 我的代码: 文件名:Controller
public function postSaveAccount(Request $request)
{
$this->validate($request, [
'first_name' => 'required| max:50'
]);
$user = Auth::user();
$user->first_name = $request['first_name'];
$user->update();
$file = $request->file('image');
$filename = $request['first_name']. '-' . $user->id . '.jpg';
if($file) {
Storage::disk('local')->put($filename, File::get($file));
}
return redirect()->route('account');
}
public function getUserImage($filename)
{
$file = Storage::disk('local')->get($filename);
return new Response($file, 200);
}
我的代码:
文件名:account.blade.php
<section class="row new-post">
<div class="col-md-6 col-md-offset-3">
<header><h3>Your Account</h3></header>
<form action="{{route('account.save')}}" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="first_name">First Name</label>
<input type="text" name="first_name" class="form-control" value="{{$user->first_name}}" id="first_name">
</div>
<div class="form-group">
<label for="image">Image (Only.jpg)</label>
<input type="file" name="image" class="form-control" id="image">
</div>
<button type="submit" class="btn btn-primary">Save Account</button>
<input type="hidden" value="{{Session::token()}}" name="_token">
</form>
</div>
</section>
@if(Storage::disk('local')->has($user->first_name. '-' . $user->id . '.jpg'))
<section class="row new-post">
<div class="col-md-6">
<img src="{{route('account.image',['filename' => $user->first_name. '-' .$user->id. '.jpg']) }}" alt="" class="img-responsive">
</div>
</section>
答案 0 :(得分:0)
您可以上传这样的图片:
import numpy as np
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
import matplotlib.pyplot as plt
import commands
import sys
patches = []
SquareList = []
StartingSquare = np.array([0,0,1,1])
SquareList.append(StartingSquare)
fig = plt.subplots()
polygon = plt.Polygon(np.reshape(np.array([0,0,.5,0,.5,1,0,1]),(4,2)))
plt.gca().add_patch(polygon)
#plt.axis('off')
plt.savefig("test.png")