| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * @package VikBooking |
| 4 | 4 | * @subpackage core |
| 5 | 5 | * @author E4J s.r.l. |
| 6 | - * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. | |
| 6 | + * @copyright Copyright (C) 2026 E4J s.r.l. All Rights Reserved. | |
| 7 | 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | 8 | * @link https://vikwp.com |
| 9 | 9 | */ |
| 10 | 10 | |
| @@ -15,9 +15,9 @@ | ||
| 15 | 15 | * This class holds the information of a generic chat attachment. |
| 16 | 16 | * |
| 17 | 17 | * @since 1.8 |
| 18 | 18 | */ |
| 19 | -class VBOChatAttachment implements JsonSerializable | |
| 19 | +class VBOChatAttachment implements JsonSerializable | |
| 20 | 20 | { |
| 21 | 21 | /** |
| 22 | 22 | * The relative source path of the attachment. |
| 23 | 23 | * |
| @@ -210,8 +210,37 @@ | ||
| 210 | 210 | */ |
| 211 | 211 | public function exists() |
| 212 | 212 | { |
| 213 | 213 | return JFile::exists($this->getPath()); |
| 214 | + } | |
| 215 | + | |
| 216 | + /** | |
| 217 | + * Returns the blob of the file in base 64 format. | |
| 218 | + * | |
| 219 | + * @return string | |
| 220 | + * | |
| 221 | + * @since 1.8.8 | |
| 222 | + */ | |
| 223 | + public function getBase64() | |
| 224 | + { | |
| 225 | + if (!$this->exists()) { | |
| 226 | + throw new RuntimeException('Missing [' . $this->getName() . '] attachment.', 404); | |
| 227 | + } | |
| 228 | + | |
| 229 | + $blob = ''; | |
| 230 | + | |
| 231 | + // open file in read mode | |
| 232 | + $fp = fopen($this->getPath(), 'r'); | |
| 233 | + | |
| 234 | + // read blob chunk by chunk | |
| 235 | + while (!feof($fp)) { | |
| 236 | + $blob .= fgets($fp, 8192); | |
| 237 | + } | |
| 238 | + | |
| 239 | + fclose($fp); | |
| 240 | + | |
| 241 | + // return base64 encoded version | |
| 242 | + return 'data:' . $this->getMimeType() . ';base64,' . base64_encode($blob); | |
| 214 | 243 | } |
| 215 | 244 | |
| 216 | 245 | /** |
| 217 | 246 | * @inheritDoc |