Laravel 文件上传:从服务器访问文件
Laravel File Uploads: Accessing the file from server
我已使用 Laravel 5.0 成功将图像文件上传到服务器。这是我的表格:
<html>
<head>
<title>Uploads</title>
</head>
<body>
{!! Form::open(array('url' => 'uploadProcessing' , 'enctype' => 'multipart/form-data')) !!}
{!! Form::label('image','Upload Image') !!}
{!! Form::file('image') !!}
{!! Form::submit('Submit') !!}
{!! Form::close() !!}
</body>
</html>
这是我的控制器:
public function uploadProcessing() {
$image = Input::file('image');
$imageName = rand(1111, 9999) . '.' . Input::file('image')->getClientOriginalExtension();
Input::file('image')->move(base_path() . '/public/uploads/', $imageName);
}
与此同时,我将 $imageName
保存为数据库 table 中的引用。
现在我必须在具有该参考的视图中显示该图像。我正在尝试以这种方式访问它:
@foreach($result as $r)
{!! HTML::image('uploads/$r->reference') !!}
@endforeach
但是它不起作用,有什么帮助吗?
我明白了,很简单,我试过这个:
<img src="..\uploads\{!! $r->reference !!}" />
成功了
我已使用 Laravel 5.0 成功将图像文件上传到服务器。这是我的表格:
<html>
<head>
<title>Uploads</title>
</head>
<body>
{!! Form::open(array('url' => 'uploadProcessing' , 'enctype' => 'multipart/form-data')) !!}
{!! Form::label('image','Upload Image') !!}
{!! Form::file('image') !!}
{!! Form::submit('Submit') !!}
{!! Form::close() !!}
</body>
</html>
这是我的控制器:
public function uploadProcessing() {
$image = Input::file('image');
$imageName = rand(1111, 9999) . '.' . Input::file('image')->getClientOriginalExtension();
Input::file('image')->move(base_path() . '/public/uploads/', $imageName);
}
与此同时,我将 $imageName
保存为数据库 table 中的引用。
现在我必须在具有该参考的视图中显示该图像。我正在尝试以这种方式访问它:
@foreach($result as $r)
{!! HTML::image('uploads/$r->reference') !!}
@endforeach
但是它不起作用,有什么帮助吗?
我明白了,很简单,我试过这个:
<img src="..\uploads\{!! $r->reference !!}" />
成功了