PHP form with upload file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am running some PHP pages on IIS 6.0.  I have created a form that allows 
the user to fill in some data and attach a file such as a pdf.  When the 
user presses the submit button, the information the user filled in on the 
form is emailed me with the attachment.  All the information comes through 
just fine, however the attachment has an error:

Error message as follows: Acrobat could not open 'test.pdf' because it is 
either not a supported file type or because the file has been damaged (for 
example, it was sent as an email attachment and wasn't correctly decoded).

Here is the code I am using:

//Attachment Start
$fileatt      = $_FILES['fileatt']['tmp_name'];
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = $_FILES['fileatt']['name'];

$headers = "From: ".$from;

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";

$data = chunk_split(base64_encode($data));

$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";


//Attachment End


thanks!

Christian 



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


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux