Sample code for 30+ languages & platforms
PHP Extension

Get Contents of File as Base64

See more Encryption Examples

Demonstrates how to read the contents of a file and convert to a base64 string.

Chilkat PHP Extension Downloads

PHP Extension
<?php

include("chilkat.php");

$success = false;

$bd = new CkBinData();

$success = $bd->LoadFile('qa_data/jpg/starfish.jpg');
if ($success == false) {
    print 'Failed to load file.' . "\n";
    exit;
}

print $bd->getEncoded('base64') . "\n";

// If you want mult-line base64:
print '--' . "\n";
print $bd->getEncoded('base64_mime') . "\n";

// If you want hex..
print '--' . "\n";
print $bd->getEncoded('hex') . "\n";

// etc.

?>