【问题标题】:move_uploaded_file(): Unable to move 'C:\xampp\tmp\php4496.tmp' to 'public/upload/member_new\BOm3f0T1kL.png' in Laravel 8move_uploaded_file():无法在 Laravel 8 中将 'C:\xampp\tmp\php4496.tmp' 移动到 'public/upload/member_new\BOm3f0T1kL.png'
【发布时间】:2021-08-17 23:33:38
【问题描述】:

我试过这样。

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' 到 'public/upload/member_new\BOm3f0T1kL.png')。

【问题讨论】:

  • 尝试$upload_path = public_path('upload/member_new')); 并确保您在公共文件夹中有目录
  • 谢谢,但不起作用。同样的错误。

标签: laravel


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2014-01-28
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 2022-11-25
    • 2020-01-20
    • 2017-02-28
    • 2020-02-26
    相关资源
    最近更新 更多