Php Laravel将图像链接到基本路径

Php Laravel将图像链接到基本路径,php,laravel,public-html,Php,Laravel,Public Html,希望将我的所有用户上传的图像移到公共视图之外 我的结构如下: Mamp htdocs buildsanctuary /app /public_html / images /user_images 我曾经用以下链接到图像: {{ asset('/')}} images/linktoimage.jpeg 但是,我现在链接如下: <?php echo base_path() ?> /user_images/linktoim

希望将我的所有用户上传的图像移到公共视图之外

我的结构如下:

Mamp
  htdocs
    buildsanctuary
      /app
      /public_html
        / images
      /user_images
我曾经用以下链接到图像:

{{ asset('/')}} images/linktoimage.jpeg
但是,我现在链接如下:

<?php echo base_path() ?> /user_images/linktoimage.jpeg

所以我不知道为什么这不起作用?有什么想法吗?

因为浏览器无法直接访问公共目录以外的文件。
如果可以的话,我会把它们放在公用文件夹里。但是,如果您确实需要移动它们(例如,为了保护它们,只有经过身份验证的用户才能查看图片),您可以创建一个路由,然后读取文件并返回:

Route::get('user_images/{filename}', array('as' => 'user_images', function($filename){
    if(!File::exists($path)){
        App::abort(404);
    }
    $guesser = Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser::getInstance();
    $mimeType = $guesser->guess($path);
    return Response::make(File::get($path), 200, array('Content-Type' => $mimeType));
}))->where('filename', '.*');
现在,您可以在视图中使用此选项:

{{ route('user_images', 'linktoimage.jpeg') }}

因为浏览器无法直接访问公用目录以外的文件。您需要添加一个路由,然后读取并返回图像。啊,这是合乎逻辑的。好的,谢谢!
{{ route('user_images', 'linktoimage.jpeg') }}