在线文档教程

php图片保存到本地

$imageData = file_get_contents($vo['icons']);
$base64Image = base64_encode($imageData);
$pos = strpos($base64Image, ',');
if ($pos !== false) {
    $base64Image = substr($base64Image, $pos + 1);
}
$tempFilePath = tempnam(sys_get_temp_dir(), 'img');
file_put_contents($tempFilePath, base64_decode($base64Image));
$imageInfo = getimagesize($tempFilePath);
$mime = $imageInfo['mime'];
$ext = mime2ext($mime);
$targetPath = './public/uploads/doc/';
$fileName = 'icon_'.uniqid().'.'.$ext;
file_put_contents($targetPath . $fileName, base64_decode($base64Image));
$path = request()->domain().'/public/uploads/doc/'.$fileName;
return $path;