Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 存储文件夹的图像路径不正确:Laravel 5.2.31_Php_Laravel_Laravel 5_Laravel 5.1_Laravel 5.2 - Fatal编程技术网

Php 存储文件夹的图像路径不正确:Laravel 5.2.31

Php 存储文件夹的图像路径不正确:Laravel 5.2.31,php,laravel,laravel-5,laravel-5.1,laravel-5.2,Php,Laravel,Laravel 5,Laravel 5.1,Laravel 5.2,刀片中有以下图像标签。 {!! Form::image('/MySplash/1/file.png', $alt="Photo", null) !!} Route::get('MySplash/{IconID}/{UniqueFileName}', function ($IconID, $filename) { $path = storage_path() . '/SplashScreenIcons/' . $IconID . '/' . $filename; if(!Fil

刀片中有以下图像标签。

{!! Form::image('/MySplash/1/file.png', $alt="Photo", null) !!}
Route::get('MySplash/{IconID}/{UniqueFileName}', function ($IconID, $filename)
{
    $path = storage_path() . '/SplashScreenIcons/' . $IconID . '/' . $filename;

    if(!File::exists($path)) {
        abort(404);
    }

    $file = File::get($path);
    $type = File::mimeType($path);

    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);

    return $response;;
});
http://localhost/SportsApp/public/MySplash/1/file.png
下面是我在路由文件中的代码。

{!! Form::image('/MySplash/1/file.png', $alt="Photo", null) !!}
Route::get('MySplash/{IconID}/{UniqueFileName}', function ($IconID, $filename)
{
    $path = storage_path() . '/SplashScreenIcons/' . $IconID . '/' . $filename;

    if(!File::exists($path)) {
        abort(404);
    }

    $file = File::get($path);
    $type = File::mimeType($path);

    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);

    return $response;;
});
http://localhost/SportsApp/public/MySplash/1/file.png
最后我得到了如下所示的图像url。

{!! Form::image('/MySplash/1/file.png', $alt="Photo", null) !!}
Route::get('MySplash/{IconID}/{UniqueFileName}', function ($IconID, $filename)
{
    $path = storage_path() . '/SplashScreenIcons/' . $IconID . '/' . $filename;

    if(!File::exists($path)) {
        abort(404);
    }

    $file = File::get($path);
    $type = File::mimeType($path);

    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);

    return $response;;
});
http://localhost/SportsApp/public/MySplash/1/file.png
有什么问题

  • 这条路不通
  • Url显示为公共。而映像文件夹位于存储目录中
  • 我遗漏了什么吗?

    表单::image()创建一个使用文件资源的HTML输入。呈现此输入及其图像的路径将直接调用您的
    GET
    路径。该框架假定您提供了一个静态路径,并在默认情况下将其简单地映射到
    public
    目录,以便浏览器检索资源

    您将图标保留在
    存储器中
    ,这意味着这些文件不公开。如果您在基于Linux的环境中工作或在本地使用Homestead,要使图标在客户端可用,最简单的方法是创建一个从
    公用
    文件夹到
    存储
    的符号链接,如下所示:

    ln -s /home/vagrant/Code/myproject/storage/SplashScreenIcons /home/vagrant/Code/myproject/public/MySplash
    
    然后,您可以像往常一样使用表单帮助器:

    {!! Form::image('/MySplash/1/file.png', $alt="Photo", null) !!}
    
    或者使用
    asset()
    帮助程序:

    <input src="{{'MySplash/1/file.png'}}" type="image">
    
    
    

    需要记住的一点是,您的产品也需要符号链接,例如作为部署挂钩。

    我想,至少您知道路由不起作用的原因。不过,很确定有一种方法可以在Windows上创建符号链接。最后,您的生产服务器在Windows上运行的可能性有多大?此外,你真的应该尝试拉维尔家园了,它很容易设置和非常方便。创建一个路由来处理简单的文件资源检索(开箱即用)似乎有些过分,我会重新考虑这一点。祝你好运。我也试过这个:但没用。你能检查一下那里的解决方案吗?