So I'm trying to generate and save an Excel-file to the server. This works flawlessly with PHPExcel. The next step is to read the file, e-mail it as an attachment and then delete it.
For some reason, PHP does not recognize xlsx as a proper file:
/* excel is generated before here */
$filename = "/results/excel/export-" . $today . ".xlsx";
$writer = new PHPExcel_Writer_Excel2007($exc);
$writer->save($filename);
/* so far so good; the file is created and exists on the server */
$to = "someone@domain.com";
$sendermail = "no-reply@domain.com";
$from = "Sender <" . $sendermail . ">";
$subject = "Email with attachment";
$message = "Here you go";
$file = $filename;
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers = "From: $from";
$headers .= "
MIME-Version: 1.0
" . "Content-Type: multipart/mixed;
" . " boundary=\" {$mime_boundary}\"";
$message = "--{$mime_boundary}
" . "Content-Type: text/plain; charset=\"iso-8859-1\"
" .
"Content-Transfer-Encoding: 7bit
" . $message . "
";
if(is_file($file)) {
$message .= "--{$mime_boundary}
";
$fp = @fopen($file, "rb");
$data = @fread($fp, filesize($file));
@fclose($fp);
$data = chunk_split(base64_encode($data));
$message .= "Content-Type: application/octet-stream; name=\"" . basename($file). ";
" . "Content-Transfer-Encoding: base64
" . $data . "
";
$message .= "--{$mime_boundary}--";
$returnpath = "-f" . $sendermail;
mail($to, $subject, $message, $headers, $returnpath);
} else {
echo("This is not a file: " . $file);
}
Which always gives me "This is not a file...". How do I read the XLSX-file?