我打算将“annonces\ August2020 \ image.jpg”之类的图像链接插入到数据库和存储中的图像中,但它给了我错误未定义的变量:插入。
文件控制器.php
public function save(Request $request)
{
request()->validate(['file' => 'required|mimes:doc,docx,pdf,txt,jpeg,jpg|max:2048',]);
if ($files = $request->file('fileUpload')) {
$destinationPath = 'public/file/'; // upload path
$profilefile = date('YmdHis') . "." . $files->getClientOriginalExtension();
$files->move($destinationPath, $profilefile);
$insert['file'] = "$profilefile";
}
$check = Document::insertGetId($insert);
return Redirect::to("file")
->withSuccess('Great! file has been successfully uploaded.');
}
文件.balde.php
<form action="/save" method="post" enctype="multipart/form-data">
@csrf
<div class="form-group">
<input type="file" class="form-control-file" name="file" id="file" aria-describedby="fileHelp">
<small id="fileHelp" class="form-text text-muted">Please upload a valid image file. Size of image should not be more than 2MB.</small>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
网页.php
Route::get('file', 'fileController@index');
Route::post('save', 'fileController@save');
哈士奇WWW
MMTTMM
慕的地10843