i have a database where are stored all email in raw mode.
I extract data with good library https://github.com/php-mime-mail-parser/php-mime-mail-parser, in particular attachments.
Now, from html page i have:
$.ajax({
async: false,
type: "POST",
url: "/mail/get/attachment",
data: {
'idMail' : idMail,
'filename' : filename
},
success: function(data){
cl(data);
},
error: function(data){
}
}).done(function (data) {
});
this call my method php:
$parser = new PhpMimeMailParser\Parser();
$parser->setText($mail['rawContent']);
$attachments = $parser->getAttachments();
foreach ($attachments as $attachment) {
if ($attachment->getFilename() == $filename){
$file = $attachment->getContent();
$size = strlen($file);
@ob_start('');
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Type: application/download');
header('Content-Description: File Transfer');
header('Content-Transfer-Encoding', 'binary');
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
header('Content-Length: '.$size);
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
ob_clean();
flush();
readfile($file);
As evidenced by the response, everything seems correct but none response show.
The filesize of attachment is correct...i have only string for calculate it. I don't want download on filesystem.
If i change the ajax client request from "async: false" into "async : true" the chrome console give me the error "net::ERR_CONTENT_LENGTH_MISMATCH".
Where i wrong ?
I don't want to get to the point of having to download the messages on the server every time and then use a simple url to recover it since I already have everything in the database.
What solution can i use?
Thanks!
## UPDATEob_clean();
echo $file;
flush();
This procedure return this in console but the download not start.