/ Published in: PHP
                    
                                        
**Example of use:**
    
echo base64DataUri('/var/www/html/background.png');
*or*
echo base64DataUri('http://static.php.net/www.php.net/images/php.gif');
                echo base64DataUri('/var/www/html/background.png');
*or*
echo base64DataUri('http://static.php.net/www.php.net/images/php.gif');
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
/**
* 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";
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                