Welcome Guest, Not a member yet? Register   Sign In
codigniter and image download problem
#4

[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.


Messages In This Thread
codigniter and image download problem - by El Forum - 10-31-2008, 07:08 AM
codigniter and image download problem - by El Forum - 10-31-2008, 10:52 AM
codigniter and image download problem - by El Forum - 11-15-2008, 07:39 PM
codigniter and image download problem - by El Forum - 11-16-2008, 03:42 PM
codigniter and image download problem - by El Forum - 11-16-2008, 05:42 PM
codigniter and image download problem - by El Forum - 01-15-2009, 04:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB