我需要将图像存储在路径为[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的含义,但是我的访问权限已调整为在我的项目文件夹中创建文件。
尝试使用包含[$image->storeAs('public/uploads', $filename);
,作为store和storeAs方法使用'storage / app'作为参考文件夹。
store方法的内置功能,您不必自己生成它。