【发布时间】:2020-05-11 11:59:30
【问题描述】:
我是 laravel 的新手
我刚刚成功上传了一张图片并在数据库中存储了名称。 也将“公共”文件夹链接到“存储/应用程序/公共”,但无法在页面上显示。 图像也在具有受保护随机名称的文件夹上。 我也无法使用该网址加载图像“http://localhost:8000/storage/flower.jpg”。 我现在该怎么办????
web.php
Auth::routes();
Route::post('/update/{id}','HomeController@update')->name('update');
Route::get('/home', 'HomeController@index')->name('home');
HomeContoller.php
public function update(Request $request,$id){
$student = user::find($id);
if ($file = $request->file('profile_image')) {
$file = $request->file('profile_image');
$request->file('profile_image')->store('public/');
$img_nm = $file->getClientOriginalName();
$request->file('profile_image')->getClientOriginalName();
$student->image = $img_nm;
}
$student->username = $request ->username;
$student->first_name = $request ->first_name;
$student->last_name = $request ->last_name;
$student->gender = $request ->gender;
$student->email = $request ->email;
$student -> save();
return redirect()->route('home');
}
home.blade.php
<td>
<img src="{{ asset('storage/'.$student-> image) }}"/>
</td>
文件系统.php
'default' => env('FILESYSTEM_DRIVER', 'local'),
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
【问题讨论】:
-
你能展示更多你的代码吗?
-
先生,我已经更新了我的代码。请帮帮我。如果需要更多问我。谢谢
-
"将 'public' 文件夹链接到 'storage/App/public'" 你在使用符号链接吗?请注意,要使用链接 - 您的项目需要
Options Indexes FollowSymLinks<Directory>在您的 apache 站点配置中。
标签: php laravel image file-upload laravel-blade