There are a bunch of existing questions similar to this one, none of them answer my problem though. It's to do with dynamically generating and downloading images in chrome. Using the example from the php site;
http://php.net/manual/en/function.imagejpeg.php
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');
// Output the image
imagejpeg($im);
// Free up memory
imagedestroy($im);
?>
If I put this into "export.php" and link to it, I get the image as expected. I want this to be a download though, so that the user clicks the link and the image downloads rather than appears in their browser. Allegedly the way to do this is with the content-disposition tag, like so;
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, 'A Simple Text String', $text_color);
// Set the content type header - in this case image/jpeg
header('Content-Type: image/jpeg');
//This is literally the only line I have added
header('Content-Disposition: attachment; filename="foo.jpg"');
// Output the image
imagejpeg($im);
// Free up memory
imagedestroy($im);
?>
And now the image no longer displays (as expected) and all works in all browsers EXCEPT chrome, which now "cancels" the image download when it's done downloading (according to dev tools) - also complains that Resource interpreted as Document but transferred with MIME type image/jpeg
in the console.
I have tried every response header under the sun, what am I doing wrong?
response headers:
Cache-Control:max-age=0 Connection:Keep-Alive Content-Disposition:attachment; filename="foo.jpg" Content-Length:1302 Content-Type:image/jpeg Date:Mon, 14 Oct 2013 09:55:32 GMT Expires:Mon, 14 Oct 2013 09:55:32 GMT Keep-Alive:timeout=15, max=43 Server:Apache/2.2.16 (Debian) X-Powered-By:PHP/5.3.3-7+squeeze15
EDIT
I was trying to simplify the description here but it seems like in simplifying I may have missed out the bit that is causing the issue. The link kicks off some ajax, which generates a POST to the page mentioned above.