Data URI base64 PHP函数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Data URI base64 PHP函数相关的知识,希望对你有一定的参考价值。
**Example of use:**echo base64DataUri('/var/www/html/background.png');
*or*
echo base64DataUri('http://static.php.net/www.php.net/images/php.gif');
/** * Data URI base64 PHP function. * * @author Pierre-Henry Soria <[email protected]> * @copyright (c) 2012-2013, Pierre-Henry Soria. All Rights Reserved. * @license Lesser General Public License (LGPL) <http://www.gnu.org/copyleft/lesser.html> * @param string $sFile The path of your file to encode. * @return string The encoded data in base64. */ function base64DataUri($sFile) { // Switch to right MIME-type switch($sExt) { case 'gif': case 'jpg': case 'png': $sMimeType = 'image/'. $sExt; break; case 'ico': $sMimeType = 'image/x-icon'; break; case 'eot': $sMimeType = 'application/vnd.ms-fontobject'; break; case 'otf': case 'ttf': case 'woff': $sMimeType = 'application/octet-stream'; break; default: } return "data:$sMimeType;base64,$sBase64"; }
以上是关于Data URI base64 PHP函数的主要内容,如果未能解决你的问题,请参考以下文章