[eluser]simonmaddox[/eluser]
[quote author="alectrash" date="1225476483"]Hi there, was wondering if anybody knows how to download image with codeigniter.
I can force downloads of pdfs, mp3s, videos, but JPG IMAGES DONT WORK, THEY ARE ALWAYS CORRUPT and won’t open. I
I have no idea why? it works fine outside of codeigniter, so it must be something to do with CI.
Here is normal image download code, which can work in a codeigniter function like so.
Code:
header('Content-type: image/jpeg');
header('Content-Disposition: attachment; filename="'. $data['filename'] . '"');
header("Content-Length: " . $data['filesize']);
readfile("/var/www/files/" . $data['filename']);
but after this did not work for images I then tried:
Code:
$imagedata = file_get_contents("/var/www/files/" . $data['filename']);
$name = $data['filename'];
force_download($name, $imagedata);
again it works for pdfs, mp3s, archives etc, but just not jpeg image files?
Does anybody have any ideas? much appreciatd at a dead end with this know.[/quote]
Try commenting out the Content-Type header - you might find that unexpected things are being output - look out for newlines.