未在文件夹中创建图像文件

问题描述 投票:0回答:1

我需要将图像存储在路径为[project/public/uploads的文件夹中。我的uploadImage函数捕获了参数图像,但未创建文件。

public function uploadImage($image)
{
    $random = Str::random(10);
    if($image == null) { return; }
    $this->removeImage();
    $filename = $random . '.' . $image->extension();
    $image->storeAs('uploads', $filename);
    $this->image = $filename;
    $this->save();
}

dd($image)显示此

Illuminate\Http\UploadedFile {#270 ▼
  -test: false
  -originalName: "korabl_more_zakat_luna_63381_1920x1080.jpg"
  -mimeType: "image/jpeg"
  -error: 0
  #hashName: null
  path: "/tmp"
  filename: "phpfJOzTp"
  basename: "phpfJOzTp"
  pathname: "/tmp/phpfJOzTp"
  extension: ""
  realPath: "/tmp/phpfJOzTp"
  aTime: 2020-02-07 18:51:11
  mTime: 2020-02-07 18:51:11
  cTime: 2020-02-07 18:51:11
  inode: 34603072
  size: 425567
  perms: 0100600
  owner: 1000
  group: 1000
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
}

也许这是我正在使用Linux OS的含义,但是我的访问权限已调整为在我的项目文件夹中创建文件。

laravel laravel-5
1个回答
0
投票

尝试使用包含[文件夹的path如下:$image->storeAs('public/uploads', $filename);,作为store和storeAs方法使用'storage / app'作为参考文件夹。

还有一件事-您不让Laravel为自己生成唯一文件名的任何原因吗?它是

store方法的内置功能,您不必自己生成它。

© www.soinside.com 2019 - 2024. All rights reserved.