Laravel把image转换成base64
方式一
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ImageController extends Controller
{
public function store(Request $request){
$image = base64_encode(file_get_contents($request->file('image')->path()));
echo $image;
}
}
方式二
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ImageController extends Controller
{
public function store(Request $request){
$image = public_path('storage/banner/15751609757424.jpg');
$base64 = base64_encode(file_get_contents($image));
echo $base64;
}
}
方式3
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ImageController extends Controller
{
public function store(Request $request){
$image = $image = storage_path('app/public/banner/15751609757424.jpg');
$base64 = base64_encode(file_get_contents($image));
echo $base64;
}
}
评论区