I’m using phpexcel to create a file.xls and then this small code i picked up to email me the xls as attachment. the problem is it sends the xls attachment as filename = "._folder1_admin.xls" instead of the actual filename "admin.xls"
It works fine if i define $filename without a sub-directory. but once i use the sub-dir like: $filename = "./folder1/".$contextUser.".xls"; it screws up the filename in email.
i tried html_entity_decode($filename) but that didnt help..
this is the only code i can see it modifying filename before sending email
chunk_split(base64_encode(file_get_contents("$filename")));
heres the whole code anyway:
$filename = "./folder1/".$contextUser.".xls";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=windows-874\n"; // or UTF-8 //
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
$strContent1 = chunk_split(base64_encode(file_get_contents("$filename")));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"$filename\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"$filename\"\n\n";
$strHeader .= $strContent1."\n\n";
Here:
You are setting the filename to the contents of
$filenmeand since./folder1/admin.xlsis not valid filename,/are normalized to underscores. You may want to usebasename($filename)in this place.