function CheckHeaders(){
if (!array_key_exists('date', $this->headers_exists)) {
$this->SetDate(NULL, TRUE);
}
if ($this->boundary == NULL) {
$this->SetBoundary();
}
}
function CheckFiles(){
if (count($this->files) == 0) {
return FALSE;
} else {
return TRUE;
}
}
function GetFile(){
$this->CheckHeaders();
if (!$this->CheckFiles()) {
exit ('No file was added.');
} //www.jb51.net
$contents = implode("\r\n", $this->headers);
$contents .= "\r\n";
$contents .= "MIME-Version: 1.0\r\n";
$contents .= "Content-Type: multipart/related;\r\n";
$contents .= "\tboundary=\"{$this->boundary}\";\r\n";
$contents .= "\ttype=\"" . $this->files[0]['mimetype'] . "\"\r\n";
$contents .= "X-MimeOLE: Produced By Mht File Maker v1.0 beta\r\n";
$contents .= "\r\n";
$contents .= "This is a multi-part message in MIME format.\r\n";
$contents .= "\r\n";
foreach ($this->files as $file) {
$contents .= "--{$this->boundary}\r\n";
$contents .= "Content-Type: $file[mimetype]\r\n";
$contents .= "Content-Transfer-Encoding: $file[encoding]\r\n";
$contents .= "Content-Location: $file[filepath]\r\n";
$contents .= "\r\n";
$contents .= $file['filecont'];
$contents .= "\r\n";
}
$contents .= "--{$this->boundary}--\r\n";
return $contents;
}
function MakeFile($filename){
$contents = $this->GetFile();
$fp = fopen($filename, 'w');
fwrite($fp, $contents);
fclose($fp);
}
function GetMimeType($filename){
$pathinfo = pathinfo($filename);
switch ($pathinfo['extension']) {
case 'htm': $mimetype = 'text/html'; break;
case 'html': $mimetype = 'text/html'; break;
case 'txt': $mimetype = 'text/plain'; break;
case 'cgi': $mimetype = 'text/plain'; break;
case 'php': $mimetype = 'text/plain'; break;
case 'css': $mimetype = 'text/css'; break;
case 'jpg': $mimetype = 'image/jpeg'; break;
case 'jpeg': $mimetype = 'image/jpeg'; break;
case 'jpe': $mimetype = 'image/jpeg'; break;
case 'gif': $mimetype = 'image/gif'; break;
case 'png': $mimetype = 'image/png'; break;
default: $mimetype = 'application/octet-stream'; break;
}
return $mimetype;
}
}
?>