我想将上传的文件存储在特定文件夹中,而不是存储在存储/应用程序文件夹中。
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)
您应该首先指定要保存的位置,然后将文件移动到该路径
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;
}