我想将上传的文件存储在特定文件夹中,而不是存储在de storage / app文件夹中。
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)
答案 0 :(得分: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;
}