I haven't been able to identify what process actually truncates the file.
All I know is that it's not my mailserver. I don't believe it's in the
coding either, as both Perl and PHP do this, and both work great otherwise.

This reads the file from the form:
        function get_file($filename){

                $return = '';
                if($fp = fopen($filename, 'rb')){
                                $return .= fread($fp, 1024);
                        return $return;

                        return FALSE;

This adds any files to a list of attachments:
        function add_attachment($file, $name = '',
$c_type='application/octet-stream', $encoding = 'base64'){
                $this->attachments[] = array(
                                                                        'body'  => 
                                                                        'name'  => 
 => $c_type,
 => $encoding

This adds a MIME subpart for the attachment:
        function &add_attachment_part(&$obj, $value){

                $params['content_type'] = $value['c_type'];
                $params['encoding']     = $value['encoding'];
                $params['disposition']  = 'attachment';
                $params['dfilename']    = $value['name'];
                $obj->addSubpart($value['body'], $params);

This is out of the build mail function, adding the text and attachments to
an e-mail:
                        case $text AND $attachments:
                                $message =& $this->add_mixed_part();
                                $this->add_text_part($message, $this->text);

                                for($i=0; $i<count($this->attachments); $i++)

Anything look wrong so far?

Just in case this may help, here's the part of the Perl script that adds
files to the e-mail. This script results in a truncation the same way as the
PHP script:

sub attachFilesToMail {
        my $type = shift;
        my $msg = shift;
        my $hasBody = shift;
        my ($key, $file);
        while (($key, $file) = each %{$CONFIG{$type}}) {
                ($debug) && print STDERR "examining attachment $key, $file\n";
                next unless ($key =~ /(\d+)file/ && -f $file);
                my $attachNum = $1;
                $file =~ m!/([^/]+)$!;
                my $filename = $1;
                my $mime_type =
                ($debug) && print STDERR "Attaching a mime type of $mime_type for
$filename ($key)\n";
                unless ($mime_type) {
                        $mime_type = (!$fhBug && -T $file) ? 'text/plain' :
                my @stats  = stat($file);
                ($debug) && print STDERR "Attaching $file ($stats[7] bytes) " .
                                                                 "to email\n";
                my $data = { Path => $file,
                                         ReadNow => 1,
                                         Filename => $filename
                unless ($mime_type =~ /^text\//) {
                        $data->{'Encoding'} = "base64";

                if (!$hasBody) {
                        $$msg->data("This is a MIME message with attachments");
                my $m = $$msg->attach(%$data);
                $m->attr("content-type" => $mime_type);
-----Original Message-----
From: Jason Wong [mailto:[EMAIL PROTECTED]]
Sent: Sunday, April 21, 2002 12:10 AM
Subject: Re: [PHP] Attachments

On Sunday 21 April 2002 06:02, Jason Soza wrote:
> They actually vary as to where they become truncated - some are at 633
> bytes, some are at 1kb. The odd thing is that the PHP script I'm using to
> process the form actually pics up the correct filesize, it reports it to
> under a $filesize variable I've setup. It'll report, say
> 69147 but the actual attachment is 1kb.

Please post your code.

> Like I said, I have this same problem using both Perl scripts and PHP
> scripts. In php.ini my post_max size is 8M and upload_max_filesize is 2M.
> Looking through the Apache mailing list archives, it looks like others
> running Apache on win32 have experienced the same problems, but there are
> no answers. I'm a little stumped myself!

Have you narrowed down the problem to whether the uploaded file is truncated
or whether the mail attachment process truncates the file?

Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *


PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to