2016-09-14 14 views
3

2つの入力ファイルを使用していますが、1つは隠しファイル、1つは表示されていますが、ここでは入力をコントローラに呼び出す方法を試してみたいが、エラーがある。メンバ関数getRealPath()null、どのようにフォームに隠されている入力ファイルを呼び出す。おかげであなたの答えフォームからの読み込みファイルの読み込み時に常にエラーが発生する

はこちらコントローラスクリプト内:ここ

public function postPhoto() 
    { 
     $photo = Input::file('photo')->getRealPath(); 

     if($this->cekUkuranFoto($photo) == false) 
     { 
      Session::flash('message', 'size too big 2048 x 2048 !'); 
      return redirect()->back(); 
     } 
} 
public function cekUkuranFoto($file) 
    { 
     $gambar = Image::make($file); 
     $ukuran = getimagesize($file); 
     $width=$ukuran[0]; 
     $height=$ukuran[1]; 

     if($width < 2048 && height < 2048) 
     { 
      return true; 
     } 
     else 
     { 
      return false; 
     } 
    } 

ビューに形成:ルートで

<form method="GET" action="{!! URL::to('/timeline/photo') !!}" files="true" enctype="multipart/form-data"> 
       <div class="box-body"> 
        <div class="form-group"> 
        <input name='photo' id="file-image" type='file' onchange="readURL(this);" style="visibility:hidden;"/> 
        <p class="help-block">Maksimal ukuran foto 1500 x 1000 pixel</p> 
        <div class="col-sm-6"> 
        <img id="image-responsive" class="img-responsive img-bordered-sm" src="{!! url('/').'/protected/public/assets/images/default.png' !!}" height=128 alt="your image"/><br/> 
        <input name="photo2" type="button" id="my-button" class ="btn btn-info" accept=".jpg,.jpeg,.png" value="Pilih Foto"> 
        <button type="button" class="btn btn-danger" onclick="hapusGambar()" >Hapus</button> 
        </div> 
        <div class="col-sm-6"> 
        <textarea name="photoinput" class="form-control" rows="6" placeholder="Deskripsi">{!! Input::old('photoinput') !!}</textarea> 
        </div> 
       </div> 
       </div> 
       <div class="box-footer"> 
        <button type="submit" class="btn btn-info pull-right">Posting</button> 
       </div> 
       </form> 

を:

Route::get('/timeline/photo', '[email protected]'); 

答えて

3

それはGET方法では動作しません。

method="GET" 

POSTに変更する必要があります。あなたのルート:

Route::post('/timeline/photo', '[email protected]'); 
+0

あなたの答えに感謝します。できます –

関連する問題