2016-10-05 2 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'); 
     } 
    } 
} 

내가 썸네일로 업로드 이미지를 테스트하는 몇 가지 코드를 추가 :

여기 내 컨트롤러 코드입니다. 그러나 실패했다.

다음은 당신이 당신의 데이터베이스에 업로드 된 경로를 저장 파일 (비디오/포스터)을 업로드해야 뷰

<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'); 
    } 

+0

고마워요. 그것의 일 : D –

+0

물론 남자. 벌써 했어. 그리고 도움에 많은 감사드립니다. 너의 지식을 퍼뜨려 라. –

관련 문제