|
 Miles Frangenberg - 2007-03-26 20:33:52
Hello, I am having issues adding an attachment from a form:
<input name="attachedfile1" type="file" size="35">
In php I use:
if (isset($_FILES['attachedfile1'])) {
$file_attachment=array(
"Name"=>$_FILES['attachedfile1']['name'],
"Data"=>$_FILES['attachedfile1'],
"Content-Type"=>"automatic/name",
"Disposition"=>"attachment"
);
$email_message->AddFilePart($file_attachment);
}
Any File that I attach seems to have the correct name but no data. How do I get this to work? I'm using email_message.php, the rest of the mailing seems to work fine.
Thanks.
 Manuel Lemos - 2007-03-26 21:09:05 - In reply to message 1 from Miles Frangenberg
Instead of
"Data"=>$_FILES['attachedfile1'],
use
"FileName"=>$_FILES['attachedfile1'],
 Miles Frangenberg - 2007-03-27 00:20:11 - In reply to message 2 from Manuel Lemos
If I use:
if (isset($_FILES['attachedfile1'])) {
$file_attachment=array(
"Name"=>$_FILES['attachedfile1']['name'],
"FileName"=>$_FILES['attachedfile1'],
"Content-Type"=>"automatic/name",
"Disposition"=>"attachment"
);
$email_message->AddFilePart($file_attachment);
}
I get: Warning: basename() expects parameter 1 to be string, array given in /home/wxvufm/public_html/globals/email_message.php on line 2148
Error: could not open part file Array
If I use:
if (isset($_FILES['attachedfile1'])) {
$file_attachment=array(
"Name"=>$_FILES['attachedfile1'],
"FileName"=>$_FILES['attachedfile1'],
"Content-Type"=>"automatic/name",
"Disposition"=>"attachment"
);
$email_message->AddFilePart($file_attachment);
}
I get the same error.
Using:
if (isset($_FILES['attachedfile1'])) {
$file_attachment=array(
"FileName"=>$_FILES['attachedfile1'],
"Content-Type"=>"automatic/name",
"Disposition"=>"attachment"
);
$email_message->AddFilePart($file_attachment);
}
I get: Warning: basename() expects parameter 1 to be string, array given in /home/wxvufm/public_html/globals/email_message.php on line 2148
Error: it was not specified the file part name
Any idea? Thanks
 Manuel Lemos - 2007-03-27 01:16:07 - In reply to message 3 from Miles Frangenberg
Sorry I meant $_FILES['attachedfile1']['tmp_name'].
 Miles Frangenberg - 2007-03-27 02:27:17 - In reply to message 4 from Manuel Lemos
Thanks so much, it works great.
How about including this in the documentation? I feel like this is a pretty common application for your class and not very straightforward at all. Everything else is documented pretty well.
Also for anyone following using this thread:
if (isset($_FILES['attachedfile1']) doesn't actually work
if ($_FILES['attachedfile1']['name']) is the only thing I had success with.
I don't think isset($_FILES['attachedfile1']['name']) worked either.
 Manuel Lemos - 2007-03-27 03:25:31 - In reply to message 5 from Miles Frangenberg
Form uploading is really outside the scope of this class, so it does not make much sense to mention that in the MIME class documentation.
What you need to read to learn about PHP file uploading is the PHP documentation:
php.net/manual/en/features.file-upl ...
As you may read there, the path of the uploaded file in the server is $_FILES['attachedfile1']['tmp_name'], not $_FILES['attachedfile1']['name'] .
 Indra Syafruddin - 2007-07-09 11:43:01 - In reply to message 6 from Manuel Lemos
When I receive the attachment, the file is always corrupt. the file format is zipped
$filename = $attachment["name"];
$text_attachment=array(
"FileName"=>$attachment["tmp_name"],
"Name"=>$filename,
"Content-Type"=>$attachment["type"],
"Disposition"=>"attachment"
);
$email_message->AddFilePart($text_attachment);
}
is there anything missing from my code ?
 Indra Syafruddin - 2007-07-13 10:22:33 - In reply to message 7 from Indra Syafruddin
another information, the same script works on linux machine with PHP 4.4.4, but not work on windows machine with PHP 4.4.3
 Manuel Lemos - 2007-07-13 19:51:11 - In reply to message 7 from Indra Syafruddin
It seems that your PHP environent has magic quotes runtime option set but for some reason it is not able to undo the magic quotes effect.
Is that a local or remote file?
Which PHP version are you using?
Can you please run this script so I can figure what can be the problem? Make sure you replace the value of "your_file_name_here" with a string with the name of the file you want to attach.
<?php
$f = "your_file_name_here";
$size=filesize($f);
if(!($file=fopen($f,"rb")))
die("could not open the file ".$f);
$body="";
while(!feof($file))
{
if(GetType($block=@fread($file,8000))!="string")
{
fclose($file);
die("could not read file ".$f);
}
$body.=$block;
}
fclose($file);
var_dump($f, $size, strlen($body), get_magic_quotes_runtime());
if((GetType($size)=="integer"
&& strlen($body)>$size)
|| (function_exists("get_magic_quotes_runtime")
&& get_magic_quotes_runtime()))
$body=StripSlashes($body);
var_dump($f, $size, strlen($body), get_magic_quotes_runtime());
?>
 Indra Syafruddin - 2007-07-16 02:18:20 - In reply to message 9 from Manuel Lemos
I'm using remote server
This is the reply for the working server :
string(8) "test.rar" int(2905) int(2905) int(0) string(8) "test.rar" int(2905) int(2905) int(0)
This is the reply for the not-working server :
string(8) "test.rar" int(2905) int(2905) int(0) string(8) "test.rar" int(2905) int(2905) int(0)
the working server use PHP 4.4.4-8
the not-working server use PHP 4.3.3
|