首页 > 解决方案 > 图片未显示在网页中(带有 Laravel 的 PHP),其他代码工作 100% 正常

问题描述

我的代码工作正常并显示存储在数据库中的内容。但不显示存储在以下位置的图像:C:\xampp\htdocs\Task_List\storage\app\fileToUpload

显示数据控制器.php

class DisplayDataController extends BaseController
{
public function displaydata()
{

    $users = DB::table('users')->select('id','email','password','pic')->get();
    return view('displaydata',['users'=> $users]);
}
}

网页.php

Route::get('/', 'DisplayDataController@displaydata' );

显示数据.blade.php

<html>

    <head>
        <title>
            Display Data
        </title>
    </head>
    <body>
    <fieldset>

    <legend>User Records</legend>
    <table>
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Password</th>        
            <th>Image</th>        
        </tr>
    </thead>
    <tr>
        @foreach($users as  $user)
            <td>{{$user->id}}</td>
            <td>{{$user->email}}</td>
            <td>{{$user->password}}</td>
            <td>
           <!-- <img src="{{ url('storage/app/fileToUpload/'.$user->pic) }}" style="height:100; width:100" />; -->


           <img src="{{ url('storage/app/fileToUpload')}}{{$user->pic}}" style="height:100; width:100" /> 

            </td>
            </tr>        
        @endforeach
    <input type="hidden" value={{csrf_token()}} name=_token>
    </table>
    </body>
</html>

唯一的问题:

<img src="{{ url('storage/app/fileToUpload')}}{{$user->pic}}" style="height:100; width:100" /> 

标签: phphtmlmysqllaravel

解决方案


尝试:

<img src="{{ url('storage/app/fileToUpload/'.$user->pic)}}" style="height:100; width:100" />

推荐阅读