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
有什么问题
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上运行的可能性有多大?此外,你真的应该尝试拉维尔家园了,它很容易设置和非常方便。创建一个路由来处理简单的文件资源检索(开箱即用)似乎有些过分,我会重新考虑这一点。祝你好运。我也试过这个:但没用。你能检查一下那里的解决方案吗?