Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#CC++MFCDelphiFoxProJavaPerlPythonRubySQL ServerVBScript

PHP Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
MIME
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip


 

 

 

 

 

 

 

 

XML Embed Binary File

Demonstrates how to embed a binary file in XML. Also extracts binary data from XML and saves to a file.

Download Chilkat FileAccess ActiveX (freeware)

Download Chilkat XML ActiveX

<?php



//  Load a binary file from disk:
$fac = new COM('Chilkat.FileAccess');
$fileData = $fac->ReadEntireFile('dude.gif');

$xml = new COM("Chilkat.Xml");

$xml->Tag = 'gifData';

//  If set to 1, the binary data is automatically compressed
//  before being added to the XML.  In this example, GIF data
//  is already a compressed file format, so we another layer
//  of compression doesn't really help much...
$zipFlag = false;

//  The data may be automatically 128-bit AES encrypted
//  if this flag is set to 1.
$encryptFlag = false;

$password = 'NotUsed';

$success = $xml->SetBinaryContent($fileData,$zipFlag,$encryptFlag,$password);

//  Examine the XML.  (The binary content is base64-encoded)
print $xml->getXml() . "\n";

//  Now extract the content to a file:
$success = $xml->SaveBinaryContent('out.gif',$zipFlag,$encryptFlag,$password);
if ($success != true) {
    print $xml->lastErrorText() . "\n";
}

//  The original data may be saved using the FileAccess component in this way:
$success = $fac->WriteEntireFile('original.gif', $fileData);
if ($success == false) {
    print $fac->lastErrorText() . "\n";
    exit;
}


?>

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.