我正在尝试使用 Storage::put 保存文件,但它总是保存一个空的图像文件,我不明白为什么。我尝试保存的文件是 base64 编码的。
这是我的代码:
$image = str_replace('data:image/png;base64,', '', $file);
$image = str_replace(' ', '+', $image);
$decodedFile = base64_decode($image);
// Image Size
$size = strlen($decodedFile);
// Image Mime Type
$f = finfo_open();
$mimeType = finfo_buffer($f, $decodedFile, FILEINFO_MIME_TYPE);
finfo_close($f);
// Extension
$extension = explode('.', $filename)[1];
$error = null;
$test = $public;
// Save file locally
Storage::put('tmp/temporary', $decodedFile);
$object = new UploadedFile($url, $filename, $mimeType, $size, $error, $test);
这就是我得到的结果,大小始终为 0
UploadedFile {#307 ▼
-test: false
-originalName: "wassho-omni-shoreham-hotel-marquee-lounge.jpg"
-mimeType: "image/png"
-size: 185463
-error: 0
path: "na_source/public/storage/tmp"
filename: "temporary"
basename: "temporary"
pathname: "na_source/public/storage/tmp/temporary"
extension: ""
realPath: "na_source/storage/app/public/tmp/temporary"
aTime: 2017-10-19 21:59:45
mTime: 2017-10-19 21:03:12
cTime: 2017-10-19 21:59:07
inode: 11166493
size: 0
perms: 0100644
owner: 1000
group: 1000
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
}
有人知道我在这里做错了什么吗?