2016-10-05 8 views
0

私は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> 
+0

あなたの問題は何ですか? –

+0

$ data配列のコメントアウトされた行が問題であると仮定します。あなたが求めているものがより明確になるように質問を更新してください。 –

+0

@RisulIslam 私はこのコードを書いたが、ファイルのアップロードには役に立たなかった。 $ file = Input :: file( 'thumbnail'); $ destinationPath = 'images /'; $ filename = $ file-> getClientOriginalName(); Input :: file( 'thumbnail') - > move($ destinationPath、$ filename); –

答えて

1

あなたは、あなたがあなたのデータベースにアップロードされたパスを保存したファイル(ビデオ/ポスター)をアップロードする必要がまずあります。

Laravels official documentation on file upload

$uniqueName = (integer)microtime(); // For unique naming vaideo/poster 
    $videoSrc = ""; 
    $thumbnailSrc = ""; 

    $file = $request->file('file');   
    // Upload video 
    $destinationPath = 'uploads/videos'; 
    $fileName = $uniqueName.'.'.$file->getClientOriginalExtension(); 
    $uploadSuccess = $file->move($destinationPath, $fileName); 
    $videoSrc = '/'.$destinationPath.'/'.$fileName; 

    $poster = $request->file('thumbnail'); 
    // Upload poster 
    $destinationPath = 'uploads/posters'; 
    $fileName = "poster".$uniqueName.'.'.$poster-  >getClientOriginalExtension(); 
    $uploadSuccess = $poster->move($destinationPath, $fileName); 
    $thumbnailSrc = '/'.$destinationPath.'/'.$fileName; 


    $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' => $videoSrc, 
     'file' => "file", 
     'thumbnail' => $thumbnailSrc, 
     'thumbnail' => "thumbnail", 
    ); 
    $i=DB::table('items')->insert($data); 
    if($i>0) 
    { 
     \Session::flash('message','new Item Saved'); 
     return redirect('itemindex'); 
    } 

(このコードは、あなたのelseステートメントのためである)

+0

ありがとうございました。その仕事:D –

+0

もちろん男。私はすでにやった。そしておかげさまで助けてくれてありがとうあなたの知識を広げてください。 –

関連する問題