Page 1 of 1

attachments have 0 bytes

Posted: Mon Jun 09, 2008 6:55 pm
by usadler
I have a mailer setup to upload a file (images, gif, jpg, etc..) to the server and also email the file.
the uploading works
and the attaching "works" in that the file shows up in the mail with the right byte size listed, however if we open the file or download it it has 0 bytes.

this is my attach line:
$sw_message->attach(new Swift_Message_Attachment(file_get_contents($_FILES['upload']['tmp_name']),($_FILES['upload']['name']),($_FILES['upload']['type'])));

the file is uploaded using a html form.
i also have tried storing the $_FILES information to
$file_path = $_FILES['upload']['tmp_name'];
$file_name = $_FILES['upload']['name'];
$file_type = $_FILES['upload']['type'];
and using the $file_bla in the $sw_message line (above)

the other options i have tried:
$sw_message->attach(new Swift_Message_Attachment( new Swift_File($file_path),$file_name,$file_type));
and also using the $_FILEs variables.

it looks like about 200 bytes are uploaded or attached and then it moves on to send the email.
any help is much appreciated.
Thank you!

Re: attachments have 0 bytes

Posted: Mon Jun 09, 2008 10:20 pm
by Chris Corbyn

Code: Select all

var_dump($_FILES);
Specifically, does $_FILES['upload']['error'] have any non-zero value?

Re: attachments have 0 bytes

Posted: Tue Jun 10, 2008 10:54 am
by usadler
It returns 0
-------
i have this
echo("<p>" . $file_path . " " . $file_name . " " . $file_type . " " . $file_size . "</p>");
returning all the correct information one line before the attachment line:

Code: Select all

 
if($file_path && $file_name && $file_type)  {
    echo("<p>" . $file_path . " " . $file_name . " " . $file_type . " " . $file_size . "</p>");
    $sw_message->attach(new Swift_Message_Attachment(file_get_contents($file_path),$file_name,$file_type));
    }
echo("<p>" . $file_path . " " . $file_name . " " . $file_type . " " . $file_size . "</p>");
echo ("<p> starting to send mail</p>");
echo ("<p>" . $_FILES['upload']['error'] . "</p>");
// Now we're ready to send the message
$swift->send($sw_message, $to, $from);
echo('<h1>Thank You For your Submission</h1>');
 

Re: attachments have 0 bytes

Posted: Tue Jun 10, 2008 5:19 pm
by Chris Corbyn

Code: Select all

var_dump(realpath($file_path));