2014-02-06 35 views
0

我想要在public/uploads文件夾中導入file.DAT。 但它沒有成功。該錯誤顯示爲需要幫助導入file.DAT到公用/上傳文件夾使用Laravel

調用成員函數getClientOriginalName()在非對象上。

這裏是我的代碼

控制器

<?php 

class ImportController extends BaseController { 

    /* 
    |-------------------------------------------------------------------------- 
    | Default Import Controller 
    |-------------------------------------------------------------------------- 
    | 
    | You may wish to use controllers instead of, or in addition to, Closure 
    | based routes. That's great! Here is an example controller method to 
    | get you started. To route to this controller, just add the route: 
    | 
    | Route::get('/', '[email protected]'); 
    | 
    */ 

    public function showImport() 
    { 
     return View::make('import'); 
    } 

    public function handleImport() 
    { 
     $file = Input::file('file'); // Your file upload input field in the form should be named 'file' 

     $destinationPath = 'public/uploads/'.str_random(8); 
     $filename = $file->getClientOriginalName(); 
     $uploadSuccess = $file->move($destinationPath, $filename); 

     if($uploadSuccess) { 
      return Response::json('success', 200); // Or do a redirect with some message that file was uploaded 
     } else { 
      return Response::json('error', 400); 
     } 
    } 
} 

查看

<form action="{{ action('[email protected]') }}" method="post" role="form"> 
    <div class="form-group"> 
     <label for="inputFile">File Import</label> 
     <input type="file" id="inputFile"> 
    </div> 
    <input type="submit" value="Import" class="btn btn-primary" /> 
</form> 

有毛病我的代碼?

回答

0

根據您的版本,Input::file('file');可以返回不同的類型。 使用dd($file)來查看$文件是什麼,基於該文件您可以檢查它是否是要繼續執行的文件。

+0

謝謝兄弟..先試試吧.. – jrdnsx