我正在尝试将图像保存到存储器中。这是我的密码
public function uploadEducationalInstitutionLogo(Request $request)
{
if ($request->hasFile('logo')) {
$file = $request->file('logo');
$fileName = time() . $file->getClientOriginalName();
$img = Image::make($file);
$img->fit(820, 312, function (Constraint $constraint) {
$constraint->upsize();
});
Storage::putFileAs('institution-logo', (string)$img->encode(null, 95), $fileName);
return response()->json([
'filename' => $fileName
]);
}
}
使用vue filepond组件作为我的图像上载程序从vue前端发出的请求:
<file-pond
name="logo"
allow-multiple="false"
max-files="1"
accepted-file-types="image/jpeg, image/png"
v-bind:files="myFiles"
:label-idle="label"
v-on:init="handleFilePondInit"
v-on:processfile="onload"
:server="server"
/>
<script>
data() {
return {
myFiles: [],
server: {
url: `http://127.0.0.1:8000/api/logo`,
process: {
headers: {
Authorization: localStorage.getItem("access_token"),
},
},
},
};
},
<script>
这里抛出以下错误:
fopen()期望参数1是一个有效的路径,在文件中给出字符串...
我想把我的照片存储在存储/图像/机构-标志/image.jpg
另一个问题是,在哪里保存最好:
1) 存储/图像/。。或者
2)公共/存储/图像/?
提前谢谢!
$data = $request->all();
foreach ($data['logo'] as $imgFile) {
$imgName = 'logo_' . random_int(111111, 999999) . '.' . $imgFile->getClientOriginalExtension();
$imgFile->move(storage_path('/images/', $imgName);
}
使用移动(storage_path);