上传我的图片时,会将其保存到D:\xampp\tmp\phpD0E0.tmp directory
。但我想将其保存在public/uploads/banner
中。有人请帮助我。这是我的代码:
BannersController.php
public function store(Request $request)
{
$requestData = $request->all();
if ($request->hasFile('banner_image')) {
foreach($request['banner_image'] as $file){
$uploadPath = public_path('/uploads/banner');
$extension = $file->getClientOriginalExtension();
$fileName = rand(11111, 99999) . '.' . $extension;
$file->move($uploadPath, $fileName);
$requestData['banner_image'] = $fileName;
}
}
Banner::create($requestData);
Session::flash('flash_message', 'Banner added!');
return redirect('Banner/banners');
}
答案 0 :(得分:0)
请将该路径恢复为'root' => storage_path('app/public')
并尝试使用更改行:
$extension = $file->getClientOriginalExtension();
$fileName = rand(11111, 99999) . '.' . $extension;
用这个:
$fileName = rand(11111, 99999) . '.' . $file->getClientOriginalName();
希望这会对你有所帮助。