私はLaravel開発の全く新しい初心者です。私は、1つのビデオアップロードとサムネイルアップロード機能と共に提出されたテキストはほとんどありません。これらのデータはすべてDBに保存できますが、私はビデオとサムネイル/画像のアップロードに悩まされています。Laravelでビデオとサムネイルをアップロードする5.1
public function save(Request $request)
{
// Any other fields to be saved here..
$post = $request->all();
// var_dump($post);
$v = \Validator::make($request->all(),
[
'title' => 'required',
'category' => 'required',
'description' => 'required',
'price' => 'required|Numeric',
'discount' => 'Numeric',
'thumbnail' => 'image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]
);
$file = Input::file('thumbnail');
$destinationPath = 'images/';
$filename = $file->getClientOriginalName();
Input::file('thumbnail')->move($destinationPath, $filename);
if($v->fails())
{
return redirect()->back()->withErrors($v->errors());
}
else
{
$data = array(
'title' => $post['title'],
'category' => $post['category'],
'partner' => $post['partner'],
'description' => $post['description'],
'published' => $post['published'],
'featured' => $post['featured'],
'price' => $post['price'],
'discount' => $post['discount'],
'file' => "file",
'thumbnail' => $filename
);
$i=DB::table('items')->insert($data);
if($i>0)
{
\Session::flash('message','new Item Saved');
return redirect('itemindex');
}
}
}
iがサムネイルとしてアップロード画像をテストするためのいくつかのコードを追加:
は、ここに私のコントローラのコードです。失敗しました。ここで
はビュー
<div class="form-group">
<label for="Thumbnail" class="col-md-3 control-label"></label>
<div class="timeline-item">
<div class="col-md-9 ">
<div class="timeline-body">
<img src="http://placehold.it/150x100" alt="..." class="margin">
</div>
</div>
</div>
</div>
あなたの問題は何ですか? –
$ data配列のコメントアウトされた行が問題であると仮定します。あなたが求めているものがより明確になるように質問を更新してください。 –
@RisulIslam 私はこのコードを書いたが、ファイルのアップロードには役に立たなかった。 $ file = Input :: file( 'thumbnail'); $ destinationPath = 'images /'; $ filename = $ file-> getClientOriginalName(); Input :: file( 'thumbnail') - > move($ destinationPath、$ filename); –