尝试将视频/电影上传到我的网站时遇到麻烦。它不会将视频保存在数据库中,但是会像预期那样在其中包含该视频的文件中创建一个“电影”文件夹。我还编辑了php.ini文件,以了解大小要求和我说的已上传的会话。这是我的代码
查看:
<div class="col-md-6">
{!! Form::open(['method'=>'POST', 'action'=> 'MovieController@store', 'files' => true]) !!}
<div class="form-group">
{!! Form::label('movie_name', 'Enter Movie Name:') !!} <br>
{!! Form::text('movie_name', null, ['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::label('uploaded_path', 'Select Movie:') !!} <br>
{!! Form::file('uploaded_path', null, ['class'=>'form-control'])!!}
</div>
</div>
<div class="form-group">
{!! Form::label('actor_id', 'Actors:') !!}
{!! Form::select('actor_id[]', $actors, null, ['class'=>'form-control js-example-basic-multiple', 'multiple' => 'multiple']) !!}
</div>
<div class="form-group">
{!! Form::label('category_id', 'Category:') !!}
{!! Form::select('category_id[]', $categories, null, ['class'=>'form-control js-example-basic-multiple', 'multiple' => 'multiple']) !!}
</div>
MovieRequest:
public function rules()
{
return [
'movie_name' => 'required|max:255',
'uploaded_path' => 'mimetypes:video/avi,video/mpeg,video/mp4|required'
];
}
控制器:
public function store(MovieRequest $request)
{
DB::beginTransaction();
try {
if ($request->hasFile('uploaded_path')) {
$filenameWithExt = $request->file('uploaded_path')->getClientOriginalName();
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
$extension = $request->file('uploaded_path')->getClientOriginalExtension();
$fileNameToStore = $filename. '_'.time().'.'.$extension;
$path = $request->file('uploaded_path')->storeAs('public/movies/', $fileNameToStore);
} else {
$fileNameToStore = 'novideo.mp4';
}
$movie = new Movie;
$movie->movie_name = $request->input('movie_name');
$movie->uploaded_path = $fileNameToStore;
$movie->actors()->attach($request->input('actor_id'));
$movie->categories()->attach($request->input('category_id'));
$movie->save();
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
}
Session::flash('success', 'A movie was successfully UPLOADED in the database!');
return redirect()->route('movies.index');
}
答案 0 :(得分:0)
别忘了添加:
$(document).ready(function(){
$('.buttons').click(function(){
if($('.active').length){
$('.active').not($(this)).removeClass('active').addClass('buttons');
}
$(this).removeClass('buttons').addClass('active');
console.log("Button " + (this).id + " Is Now Active!")
});
$("#growBtn").on("click", function() {
$("#box").animate({height:"+=15px", width:"+=15px"}, "fast");
// console.log("Grow Button Clicked!");
})
$("#shrinkBtn").on("click", function() {
$("#box").animate({height:"-=15px", width:"-=15px"}, "fast");
// console.log("Shrink Button Clicked!");
})
$("#blueBtn").on("click", function() {
$("#box").removeClass("purpleBox");
$("#box").addClass("blueBox");
// console.log("Blue Button Clicked!");
})
$("#purpleBtn").on("click", function() {
$("#box").removeClass("blueBox");
$("#box").addClass("purpleBox");
// console.log("Purple Button Clicked!");
})
$("#fadeBtn").on("click", function() {
$("#box").fadeTo( "fast", Math.random() );
// console.log("Fade Button Clicked!");
})
$("#resetBtn").on("click", function() {
$("#box").removeClass("blueBox");
$("#box").addClass("boxStyle");
$("#box").animate({opacity: "1"}, "fast");
$("#box").animate({height: "245px", width: "245px"}, "fast");
// console.log("Reset Button Clicked!");
})
})
到电影领域。