Upload videos in Laravel project
I am having trouble when I try to upload video/movie to my site. It doesn't save the video in the database, but it makes a folder 'movie' in my files with that video in it like it's supposed to. Also I edited my php.ini file for size requirements and session that I made says that it uploaded. Here is my code
View:
<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'
];
}
Controller:
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');
}
php database laravel upload
add a comment |
I am having trouble when I try to upload video/movie to my site. It doesn't save the video in the database, but it makes a folder 'movie' in my files with that video in it like it's supposed to. Also I edited my php.ini file for size requirements and session that I made says that it uploaded. Here is my code
View:
<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'
];
}
Controller:
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');
}
php database laravel upload
1
So$movie
doesn't exist - it is not defined anywhere - and even if it did you never do$movie->save()
.
– ceejayoz
Nov 13 '18 at 16:49
I edited post, it works now but I now have many to many relationship attached and now they don't work. works when I upload but it doesn't attach actors and categories. It shows in pivot tables that movie_id is null but categorry_id and actor_id shows correct ids. Can you help?
– Ivan
Nov 13 '18 at 17:17
add a comment |
I am having trouble when I try to upload video/movie to my site. It doesn't save the video in the database, but it makes a folder 'movie' in my files with that video in it like it's supposed to. Also I edited my php.ini file for size requirements and session that I made says that it uploaded. Here is my code
View:
<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'
];
}
Controller:
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');
}
php database laravel upload
I am having trouble when I try to upload video/movie to my site. It doesn't save the video in the database, but it makes a folder 'movie' in my files with that video in it like it's supposed to. Also I edited my php.ini file for size requirements and session that I made says that it uploaded. Here is my code
View:
<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'
];
}
Controller:
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');
}
php database laravel upload
php database laravel upload
edited Nov 13 '18 at 17:21
Ivan
asked Nov 13 '18 at 16:43
IvanIvan
113
113
1
So$movie
doesn't exist - it is not defined anywhere - and even if it did you never do$movie->save()
.
– ceejayoz
Nov 13 '18 at 16:49
I edited post, it works now but I now have many to many relationship attached and now they don't work. works when I upload but it doesn't attach actors and categories. It shows in pivot tables that movie_id is null but categorry_id and actor_id shows correct ids. Can you help?
– Ivan
Nov 13 '18 at 17:17
add a comment |
1
So$movie
doesn't exist - it is not defined anywhere - and even if it did you never do$movie->save()
.
– ceejayoz
Nov 13 '18 at 16:49
I edited post, it works now but I now have many to many relationship attached and now they don't work. works when I upload but it doesn't attach actors and categories. It shows in pivot tables that movie_id is null but categorry_id and actor_id shows correct ids. Can you help?
– Ivan
Nov 13 '18 at 17:17
1
1
So
$movie
doesn't exist - it is not defined anywhere - and even if it did you never do $movie->save()
.– ceejayoz
Nov 13 '18 at 16:49
So
$movie
doesn't exist - it is not defined anywhere - and even if it did you never do $movie->save()
.– ceejayoz
Nov 13 '18 at 16:49
I edited post, it works now but I now have many to many relationship attached and now they don't work. works when I upload but it doesn't attach actors and categories. It shows in pivot tables that movie_id is null but categorry_id and actor_id shows correct ids. Can you help?
– Ivan
Nov 13 '18 at 17:17
I edited post, it works now but I now have many to many relationship attached and now they don't work. works when I upload but it doesn't attach actors and categories. It shows in pivot tables that movie_id is null but categorry_id and actor_id shows correct ids. Can you help?
– Ivan
Nov 13 '18 at 17:17
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285711%2fupload-videos-in-laravel-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53285711%2fupload-videos-in-laravel-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
So
$movie
doesn't exist - it is not defined anywhere - and even if it did you never do$movie->save()
.– ceejayoz
Nov 13 '18 at 16:49
I edited post, it works now but I now have many to many relationship attached and now they don't work. works when I upload but it doesn't attach actors and categories. It shows in pivot tables that movie_id is null but categorry_id and actor_id shows correct ids. Can you help?
– Ivan
Nov 13 '18 at 17:17