laravel中图片转base64的方法

这里的核心是读取文件内容,而不是直接拿着提交的file编码,示例代码如下,

 

 if ($request->hasFile('file')) {
            $file = $request->file('file');
            $content = file_get_contents($file->getRealPath()); // 读取文件内容
            $base64 = base64_encode($content);

 

  • 当前日期:
  • 北京时间:
  • 时间戳:
  • 今年的第:18周
  • 我的 IP:3.148.240.165
农历
五行
冲煞
彭祖
方位
吉神
凶神
极简任务管理 help
+ 0 0 0
Task Idea Collect