这里的核心是读取文件内容,而不是直接拿着提交的file编码,示例代码如下,
if ($request->hasFile('file')) { $file = $request->file('file'); $content = file_get_contents($file->getRealPath()); // 读取文件内容 $base64 = base64_encode($content);