base64_encode corrupts files?
| From: | Imposible | Date: | Fri, 18 Jul 2003 10:40:50 +0000 |
| Subject: | base64_encode corrupts files? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-155753@lists.php.net to get a copy of this message | ||
Hi,
I trying to send a binary file (exe, zip, etc etc) that is attached using mail() function.
I'm do a base64_encode and chunk_split after read the file, but the result is a corrupt file so i can't read the attached file with my mail client.
When i call the script the attached file is corrupt.
My server is Red Hat Linux 7.3, Apache 1.3.27-2, PHP 4.1.2
Any idea?
Please Help.
This is my chunk of code. <?php
// create a MIME boundary string
$boundary = "=====XXXX." . md5(uniqid(time())) . "=====";
// add MIME data to the message headers
$headers .= "MIME-Version:1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n\tboundary=\"$boundary\"\r\n\r\n";
// start building a MIME message
$str ="This is a multi-part message in MIME format.\n";
$str .= "--" . $boundary . "\r\n";
$str .= "Content-Type: text/plain;\r\n\tcharset=\"us-ascii\"\r\n";
$str .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$str .= "Hi all.\r\n\r\n";
//attach:w
$str .= "--".$boundary."\n";
$file="mapa.zip";
$str .="Content-Type: application/octet-stream; name=\"".$file."\"\n";
$str .="Content-Transfer-Encoding: base64\n";
$str .="Content-Disposition: attachment; filename=\"".$file."\"\n\n";
$fd=fopen ($file, "rb");
$FileContent=fread($fd,filesize($file));
fclose ($fd);
$FileContent=chunk_split(base64_encode($FileContent));
$str .=$FileContent;
//attach ends
$body=$str;
//send mail
mail("email@domain.es", "I am really desperated", $body, $headers);
?>