By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

copy Attachement from Email on server (files copied are not valid)

P: n/a
Hi,
I'm getting emails from an address trough a script and I want to copy the
attached files on the server. I can get the files and copy them on the
server (trough the function below) BUT the files are not valid (images
cannot be displayed)

how can I solve this?

------------------------------------------
function get_attachments($mbox,$msgno){

$o = imap_fetchstructure($mbox, $msgno);
$dir = "C:/AppServ/www/getinfo/fileadmin/testmail/"; // TEST

if ($o->type == 1 || ($o->ifsubtype == 1 && $o->subtype == 'MIXED')) {

$parts = $o->parts;
$i=1;
$retour = array();
foreach($parts as $part) {
$fname = '';

if (!isset($part->encoding) && $part->encoding == 3) {
$str = imap_base64(trim(@imap_fetchbody($mbox, $msgno,$i)));
} else {
$str = imap_fetchbody($mbox, $msgno,$i);
}
if ($part->ifdparameters == 1) {
$dparams = $part->dparameters;
foreach($dparams as $dparam) {
if ($dparam->attribute == "FILENAME") {
$fname = $dparam->value;
}
}
}
if ($fname=="") {
if ($part->ifparameters == 1) {
$params = $part->parameters;
foreach($params as $param) {
if ($param->attribute == "NAME") {
$fname = $param->value;
}
}
}
}
if ($fname=="") {$fname = "part$i";}

$fp = fopen($dir.$fname,"wb");
if (!$fp) { return FALSE; }
fwrite($fp,$str);
fclose($fp);
$i++;
}
return $retour;
} else {
return "no attach";
}
}
Jul 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"nic den" <nd******@yahoo.fr> wrote in message
news:3f********@news.swissonline.ch...
Hi,
I'm getting emails from an address trough a script and I want to copy the
attached files on the server. I can get the files and copy them on the
server (trough the function below) BUT the files are not valid (images
cannot be displayed)

how can I solve this?

<snip users untested code>

Aren't e-mail attachments Base64 encoded?
Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.