Sample code for 30+ languages & platforms
Perl

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 Perl Downloads

Perl
use chilkat();

$success = 0;

$bd = chilkat::CkBinData->new();

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

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

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

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

# etc.