在laravel 5.4中上传图片时,移动'tmp'目录不起作用

时间:2017-06-19 05:31:40

标签: php laravel laravel-5.4

上传我的图片时,会将其保存到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');
}

1 个答案:

答案 0 :(得分:0)

请将该路径恢复为'root' => storage_path('app/public')

并尝试使用更改行:

$extension = $file->getClientOriginalExtension();
$fileName = rand(11111, 99999) . '.' . $extension;

用这个:

$fileName = rand(11111, 99999) . '.' .  $file->getClientOriginalName();

希望这会对你有所帮助。