|
Posted by JAKE on 11/15/67 11:23
Hi,
I made a funstion that checks a mail account, retrieves and stores the
attachments in a folder on my website.
This works great for .doc files but not for .pdf files.
I am almost sure the problem is in: $fileContent =
imap_base64($fileContent);
Whet is the encoding for PDF attachments ?
Can someone help me with this.
Best Regards,
JAKE, Belgium
This is the script (copied the function in a standalone script, the only
thing this does is open pop account, check messages, store attachments,
close imap connection):
<?php
$login = 'mypoplogin';
$password = 'mypoppassword';
$mbox = imap_open("{127.0.0.1:110/pop3/notls}INBOX", "$login", "$password")
or die("Could not open Mailbox - try again later!");
//
// make connection with mailbox and check # messages
if ($hdr = imap_check($mbox)) {
echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>";
$msgCount = $hdr->Nmsgs;
} else { echo "failed"; }
$overview=imap_fetch_overview($mbox,"1:$msgCount",0);
$size=sizeof($overview);
// get message info
for($i=$size-1;$i>=0;$i--)
{
$val=$overview[$i];
$msg=$val->msgno;
$from=$val->from;
$date=$val->date;
$subj=$val->subject;
$seen=$val->seen;
$from = ereg_replace("\"","",$from);
// Check for attachements and store them
$struct = imap_fetchstructure($mbox,$msg);
$contentParts = count($struct->parts);
if ($contentParts >= 2) {
for ($ix=2;$ix<=$contentParts;$ix++) {
$att[$ix-2] = imap_bodystruct($mbox,$msg,$ix);
}
for ($k=0;$k<sizeof($att);$k++) {
if ($att[$k]->parameters[0]->value == "us-ascii" ||
$att[$k]->parameters[0]->value == "US-ASCII") {
if ($att[$k]->parameters[1]->value != "") {
$FileName[$k] = $att[$k]->parameters[1]->value;
$FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4));
}
} elseif ($att[$k]->parameters[0]->value != "iso-8859-1" &&
$att[$k]->parameters[0]->value != "ISO-8859-1") {
$FileName[$k] = $att[$k]->parameters[0]->value;
$FileType[$k] = strrev(substr(strrev($FileName[$k]),0,4));
$fileContent = imap_fetchbody($mbox,$msg,$file+2);
$fileContent = imap_base64($fileContent);
$localfile = fopen("/var/www/html/storedattachments/$FileName[$k]","w");
fputs($localfile,$fileContent);
fclose($localfile);
}
}
}
}
imap_close($mbox);
?>
Navigation:
[Reply to this message]
|