Laravel - 解析上传的图像路径

时间:2017-08-20 16:26:24

标签: php laravel

我上传的图片位于storage/app/spreferenceimages

图像路径以下列方式存储在DB中: spreferenceimages/laravel-generated-filename.ext

我正在尝试使用我视图中的路径。我试过asset()帮助:

<img src="{{ asset($spreference->favicon) }}">

但它会返回NotFoundException。生成的网址为:

http://localhost:3000/spreferenceimages/v2hM7nJcSWdXCAh7RdJUR4CExAMQfk1XX0u4ZiX1.png

如何直接使用存储文件夹(无需在公共文件夹中生成符号链接)?

2 个答案:

答案 0 :(得分:0)

您应该创建symbolic link

php artisan storage:link

这会创建一个从public/storagestorage/app/public的符号链接,因为最终用户只能访问storage/app/public中的内容。

然后你可以访问图像:

http://localhost:3000/storage/v2hM7nJcSWdXCAh7RdJUR4CExAMQfk1XX0u4ZiX1.png

答案 1 :(得分:0)

您可以创建访问文件的路径或将文件直接上传到公共文件夹

使用路线的例子:

java.lang.IllegalStateException: failed to create a child event loop
        at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:68)
        at io.netty.channel.MultithreadEventLoopGroup.<init>(MultithreadEventLoopGroup.java:50)
        at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:70)
        at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:65)
        at io.netty.channel.nio.NioEventLoopGroup.<init>(NioEventLoopGroup.java:56)
        at org.asynchttpclient.netty.channel.ChannelManager.<init>(ChannelManager.java:173)
        at org.asynchttpclient.DefaultAsyncHttpClient.<init>(DefaultAsyncHttpClient.java:85)
        at dispatch.Http.client$lzycompute(execution.scala:16)
        at dispatch.Http.client(execution.scala:16)
        at dispatch.Http.client(execution.scala:11)
        at dispatch.HttpExecutor$class.apply(execution.scala:120)
        at dispatch.Http.apply(execution.scala:11)
        at dispatch.HttpExecutor$class.apply(execution.scala:115)
        at dispatch.Http.apply(execution.scala:11)
        at scalaxb.DispatchHttpClientsAsync$DispatchHttpClient$class.request(httpclients_dispatch_async.scala:22)
        at scalaxb.DispatchHttpClientsAsync$$anon$1.request(httpclients_dispatch_async.scala:7)
        at scalaxb.SoapClientsAsync$SoapClientAsync$class.soapRequest(soap12_async.scala:43)
        at scalaxb.SoapClientsAsync$$anon$1.soapRequest(soap12_async.scala:24)
        at scalaxb.SoapClientsAsync$SoapClientAsync$class.requestResponse(soap12_async.scala:63)
        at scalaxb.SoapClientsAsync$$anon$1.requestResponse(soap12_async.scala:24)
Caused by: io.netty.channel.ChannelException: failed to open a new selector
    at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:176)
    at io.netty.channel.nio.NioEventLoop.<init>(NioEventLoop.java:150)
    at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:103)
    at io.netty.util.concurrent.MultithreadEventExecutorGroup.<init>(MultithreadEventExecutorGroup.java:64)
    ... 34 more
Caused by: java.io.IOException: Too many open files in system
        at sun.nio.ch.KQueueArrayWrapper.init(Native Method)
        at sun.nio.ch.KQueueArrayWrapper.<init>(KQueueArrayWrapper.java:98)
        at sun.nio.ch.KQueueSelectorImpl.<init>(KQueueSelectorImpl.java:88)
        at sun.nio.ch.KQueueSelectorProvider.openSelector(KQueueSelectorProvider.java:42)
        at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:174)
        ... 37 more