2016-07-15 50 views
0

我想將我上傳的文件存儲在特定文件夾中,而不是存儲在de/storage文件夾中。將文件上傳到另一個目錄laravel 5

public function upload(Request $request) { 
     $files = $request->file('file'); 
     foreach ($files as $file): 
     Storage::put($file->getClientOriginalName(), file_get_contents($file)); 

     endforeach; 

我試圖做到這一點,但它不工作:

public function upload(Request $request) { 

     $selectfolder = \Request::get('selectfolder'); 
     $files = $request->file('file'); 
     foreach ($files as $file): 
     storage_path(). "/download/". $selectfolder::put($file->getClientOriginalName(), file_get_contents($file)); 

     endforeach; 

Laravel給出了這樣的錯誤:
語法錯誤,意想不到的 '::'(T_PAAMAYIM_NEKUDOTAYIM)

回答

2

您應指定要先保存的位置,然後將文件移動到該路徑

public function upload(Request $request) { 
    // selected folder 
    $selectfolder = \Request::get('selectfolder'); 
    // input files 
    $files = $request->file('file'); 

    foreach ($files as $file): 

     $fileName = $file->getClientOriginalName(); 

     $pathToStore = storage_path(). "/download/". $selectfolder; 

     $file->move($pathToStore, $fileName); 

    endforeach; 
} 
相關問題