首页 > 解决方案 > move_uploaded_file():无法在 Laravel 8 中将 'C:\xampp\tmp\php4496.tmp' 移动到 'public/upload/member_new\BOm3f0T1kL.png'

问题描述

我试过这样。

if ($imageimage) {
    if ($member->image != null) {
        @unlink($member->image);
    }
    $image_name = Str::random(10);
    $ext = strtolower($imageimage->getClientOriginalExtension());
    $image_name = $image_name . '.' . $ext;
    $upload_path = 'public/upload/member_new/';

    $image_description = $upload_path . $image_name;
    $imageimage->move($upload_path, $image_name);
    if ($ext=='jpg' || $ext=='png'|| $ext=='jpeg'){
        $member->image = $image_description;
        dd('success');
    }else{
        Toastr::error('message', 'Image is not valid!!');
        return redirect()->back();
    }
}

无法将文件“C:\xampp\tmp\php4496.tmp”移动到“public/upload/member_new\BOm3f0T1kL.png”(move_uploaded_file(): Unable to move 'C:\xampp\tmp\php4496.tmp' to '公共/上传/member_new\BOm3f0T1kL.png')。

标签: laravel

解决方案


你应该使用存储 laravel。 https://laravel.com/docs/8.x/filesystem#specifying-a-file-name

$request->file->storeAs($path, $file_name, $disk);

推荐阅读