Sample code for 30+ languages & platforms
PHP Requires Chilkat v11.0.0+

Extract Files from MIME

See more MIME Examples

Extract files from a MIME message.

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\Mime;
use Chilkat2\StringTable;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$mime = new Mime();

// Load a MIME document from a file:
// (.mht and .eml files contain MIME).
try {
    $mime->LoadMimeFile('mst.mht');

    $st = new StringTable();
    $mime->PartsToFiles('/temp/mimeParts', $st);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$n = $st->Count;

// Display the paths of the files created:
$i = 0;
while ($i < $n) {
    echo $st->StringAt($i), "\n";
    $i = $i + 1;
}