AWS s3桶上的Laravel更新文件



所以目前我可以在AWS s3桶中存储文件,但我不能更新文件到目前为止,这是我尝试😅请帮助!

if($request->hasFile('uploadURL')) {
// Get filename with the extension
$filenameWithExt = $request->file('uploadURL')->getClientOriginalName();
// Get just filename
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
// Get just ext
$extension = $request->file('uploadURL')->getClientOriginalExtension();
// Filename to store
$fileNameToStore= $filename.'_'.time().'.'.$extension;
// Upload Image
$path = $request->file('uploadURL')->storeAs('public/uploads', $fileNameToStore, 's3');


} else {
$fileNameToStore = 'noimage.jpg';
}
$upload = new Uploads;
$upload->description = $request->input('description');
$upload->student_id = $request->input('student_id');
$upload->uploadURL = $fileNameToStore;
$evidence->update($request->all());

谢谢大家😁,问题解决了

if ($request->hasFile('uploadURL')) {
Storage::disk('s3')->delete('public/uploads/' . $evidence->uploadURL);
// Get filename with the extension
$filenameWithExt = $request->file('uploadURL')->getClientOriginalName();
// Get just filename
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
// Get just ext
$extension = $request->file('uploadURL')->getClientOriginalExtension();
// Filename to store
$fileNameToStore = $filename . '_' . time() . '.' . $extension;
// Upload Image
$path = $request->file('uploadURL')->storeAs('public/uploads', $fileNameToStore, 's3');
} else {
if ($evidence->uploadURL != 'noimage.jpg') {
$fileNameToStore = $evidence->uploadURL;
}
}
$upload = new Uploads;
$upload->description = $request->input('description');
$upload->student_id = $request->input('student_id');
$upload->uploadURL = $fileNameToStore;
$evidence->update($upload->toArray());

相关内容

  • 没有找到相关文章

最新更新