public function convertImgToBase64($imgFolderPath, $appID, $customerID) { $imageFolder = $imgFolderPath.$appID.‘/‘.$customerID.‘/‘; $base64EncodedArray = array(); if(is_dir($imageFolder)) { Yii::trace($imageFolder); $handler = opendir($imageFolder); while (($filename = readdir($handler)) !== false) { if ($filename != "." && $filename != "..") { $imageFilePath = $imageFolder.$filename; $imageInfo = getimagesize($imageFilePath); $base64ImageContent = "data:{$imageInfo[‘mime‘]};base64," . chunk_split(base64_encode(file_get_contents($imageFilePath))); array_push($base64EncodedArray, $base64ImageContent); } } closedir($handler); } return $base64EncodedArray; }
时间: 2024-11-08 22:23:27