在Laravel 7.x Homestead照片被正确上传到存储中,但在刀片文件中提取时没有显示



在ArticleController.php中,数据以适当的扩展名上传到存储目录中,但在主页数据库中,上传的照片数据是"/tmp/phpBqfse2">

public function store(Request $request)
{
Article::create($this->validateForm());
if ($request->hasFile('photo')) 
{
$fileName = $request->photo->getClientOriginalName();   
$request->photo->storeAs('uploads', $fileName, 'public');
}
return redirect()->route('article.index')->with('success', 'Article data has been uploaded 
successfully');
}
**In index.blade.php the data is not fetched by the following code **
<img src="{{ asset('uploads/'. $article->photo) }}" alt="Photo">
**Note**
storage is linked
php artisan storage:link

因此,当您链接存储(php artisan storage:link(时,您可以使用{{ asset('storage/and/file.png') }}访问存储。举个例子,说明您是如何尝试访问"上传"文件夹和访问jpeg的。你会这样做的:

<img src="{{ asset('storage/uploads/photo.jpeg') }}" alt="What you want">

如果文件系统是#类型:"nfs";在Homestead目录中的Homestead.yaml中,文件将不会在Windows操作系统中显示。

最新更新