当我尝试在我的网站上上传电影/视频时出现此错误,“您无权访问所请求的目录。没有索引文档,或者目录是受读保护的”。这是我的代码
视图:
<div class="col-md-6">
{!! Form::open(['method'=>'POST', 'action'=> 'MovieController@store', 'files' => true]) !!}
<div class="form-group">
{!! Form::label('movie_name', 'Select Movie:') !!}
{!! Form::file('movie_name', null, ['class'=>'form-control'])!!}
</div>
</div>
控制器:
public function store(Request $request){
$data = $request->all();
if ($request->hasFile('movie_name')) {
$file = $request->file('movie_name');
$name = $file->getClientOriginalName();
$data[ 'movie_name' ] = $name;
$destination = '/public/movies';
$request->file('movie_name')->move(base_path() . $destination, $name);
return $name;
} else {
return false;
}
}
答案 0 :(得分:2)
使用Laravel的资产助手方法指向公用文件夹。
尝试一下:
public function store(Request $request){
$data = $request->all();
if ($request->hasFile('movie_name')) {
$file = $request->file('movie_name');
$name = $file->getClientOriginalName();
$data[ 'movie_name' ] = $name;
$request->file('movie_name')->move(asset('movies'), $name);
return $name;
} else {
return false;
}
}
答案 1 :(得分:0)
尝试将“ / public / movies”权限更改为775。
sudo chmod -R 775 PATH/TO/DIRECTORY