From: Michael M Slusarz Date: Fri, 13 Mar 2009 05:20:37 +0000 (-0600) Subject: Work around some browser limitations regarding RFC 2397 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=dc97e0c56a87d17bdf388c3e4038859dcf45e519;p=horde.git Work around some browser limitations regarding RFC 2397 --- diff --git a/imp/lib/IMP.php b/imp/lib/IMP.php index 143189c9e..e020b32a1 100644 --- a/imp/lib/IMP.php +++ b/imp/lib/IMP.php @@ -1719,8 +1719,16 @@ class IMP */ public function base64ImgData($file) { - $data = file_get_contents(realpath($GLOBALS['registry']->get('fileroot', 'horde')) . preg_replace('/^' . preg_quote($GLOBALS['registry']->get('webroot', 'horde'), '/') . '/', '', $file)); - return 'data:image/' . substr($file, strrpos($file, '.') + 1) . ';base64,' . base64_encode($data); + /* Only encode image files if they are below 3,000 bytes. RFC 2397 + * only requires support of up to 1,024 characters (base64 encoded, + * not the size of the image). However, browsers that support data + * URLs generally support more. Opera seems to have the smallest + * allowance - 4100 characters - so use Opera as a limit. */ + $filename = realpath($GLOBALS['registry']->get('fileroot', 'horde')) . preg_replace('/^' . preg_quote($GLOBALS['registry']->get('webroot', 'horde'), '/') . '/', '', $file); + + return (filesize($filename) <= 3000) + ? 'data:image/' . substr($file, strrpos($file, '.') + 1) . ';base64,' . base64_encode(file_get_contents($filename)) + : $file; } /**