php图片本地化
public function img($imageUrl)
{
$imageData = file_get_contents($imageUrl);
$base64Image = base64_encode($imageData);
$pos = strpos($base64Image, ',');
if ($pos !== false) {
$base64Image = substr($base64Image, $pos + 1);
}
$binaryData = base64_decode($base64Image);
$tempFilePath = tempnam(sys_get_temp_dir(), 'img');
file_put_contents($tempFilePath, base64_decode($base64Image));
$imageInfo = getimagesize($tempFilePath);
$mime = $imageInfo['mime'];
$size = filesize($tempFilePath);
$ext = mime2ext($mime);
$targetPath = './public/uploads/Base64Image/';
$fileName = date('Y-m-d-', time()).uniqid().'.'.$ext;
file_put_contents($targetPath . $fileName, $binaryData);
$path = '/public/uploads/Base64Image/'.$fileName;
return $path;
}