I have two pages: doit.inc and doit.php
When you first visit doit.php, you get to browse for a file and either hit the submit button -- which sends an e-mail with the file attached -- or hit the confirmation page which takes you to a second page that allows you to see the name of the file you are about to send before hitting the submit button to send it.
When I hit the submit button without going through the confirmation page, the e-mail is sent and the attached file arrives intact. If I go through the confirmation page before sending the e-mail, the e-mail arrives with the file attached but the file is empty. I also get the following error:
Warning: fopen("/tmp/phpmjEPLX", "r") - No such file or directory in /home/v/l/user840907/html/doit.php on line 23
Warning: stat failed for /tmp/phpmjEPLX (errno=2 - No such file or directory) in /home/v/l/user840907/html/doit.php on line 23
Warning: Supplied argument is not a valid File-Handle resource in /home/v/l/user840907/html/doit.php on line 23
It seems as if the file is not successfully passing from one page to the next.
Any ideas?
If you are feeling bold, copy the text into two separate files, change the example@example.com e-mail address and see what you get.
Here is the text for doit.inc
<?php
session_start();
session_register('attachfile','attachfile_name','attachfile_type');
if (isset($message1))
echo
"$message1<br>
'The name of the file is $attachfile!'
<form action='doit.php' method='post' name='submit' enctype=' multipart/form-data'>
<input type='submit' name='submit' border='0' value='submit'>
</form>";
else
echo
"
<form action='doit.php' method='post' name='proceed' enctype='multipart/form-data'>
<input type='file' name='attachfile' size='16' border='0'>
<input type='submit' name='proceed' border='0' value='confirmation page'>
<input type='submit' name='submit' border='0' value='submit'>
</form>";
?>
Here is the text for doit.php
<?php
session_start();
session_register('attachfile','attachfile_name','attachfile_type');
if (isset($HTTP_POST_VARS['proceed']))
{
$message1="Hit the submit button to submit your request!";
include ("doit.inc");
}
else
if (isset($HTTP_POST_VARS['submit']))
{
function sendmsg
(
$to,
$subject,
$text,
$from,
$file,
$type,
$name
)
{
$content = fread(fopen($file,"r"),filesize($file));
$content = chunk_split(base64_encode($content));
$uid = strtoupper(md5(uniqid(time())));
$header = "From: $from\nReply-To: $from\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=$uid\n";
$header .= "--$uid\n";
$header .= "Content-Type: text/plain\n";
$header .= "Content-Transfer-Encoding: 8bit\n\n";
$header .= "$text\n";
$header .= "--$uid\n";
$header .= "Content-Type: $type; name=\"$name\"\n";
$header .= "Content-Transfer-Encoding: base64\n";
$header .= "Content-Disposition: attachment; filename=\"$name\"\n\n";
$header .= "$content\n";
$header .= "--$uid--";
mail($to, $subject, "", $header);
return true;
}
echo "An e-mail was sent to example@example.com!<br>";
echo "If you ask to print dollarsignfile, you get: $file<br>";
echo "boo<br>";
echo "If you ask to print dollarsignattachfile, you get: $attachfile";
sendmsg ("example@example.com",
"Periodical - Current Issue",
"Greetings from the folks at Periodical! Attached is Periodical for the week the appropriate week.
Enjoy! We'll see you out and about.
As always, if you need to change your subscription e-mail
address, temporarily suspend your subscription, or you need any other type of customer service, a link is always available on our home page at http://www.periodical.com.",
"customerservice@periodical.com",
$attachfile,
$attachfile_type,
$attachfile_name);
$message1 = "secondpage";
}
else
{
include ("doit.inc");
}
?>