CodeIgniter Forums
Download File Bug: weird characters ! - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Download File Bug: weird characters ! (/showthread.php?tid=18647)



Download File Bug: weird characters ! - El Forum - 05-13-2009

[eluser]yannyannyann[/eluser]
Hi everyone,

I have a bug on my site, when user clicks my DOWNLOAD FILE button, the image, video or sound file doesn't get downloaded but the browser displays characters, here an extract :
Code:
�����JFIF���������;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90 ���C�     ���C    ���,�"�������������� �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz����������������������������������������������������������������������������������� �����

My code was working before on another server...

What could be the reason for that ?


Download File Bug: weird characters ! - El Forum - 05-13-2009

[eluser]cairo140[/eluser]
Looks like you may be sending out faulty headers. If the file downloads with the proper extension, and the end user still can't open it, post a reply, and we'll try to help you out.

You can force a download using PHP headers: How to Force Downloads


Download File Bug: weird characters ! - El Forum - 05-13-2009

[eluser]Thorpe Obazee[/eluser]
or you can use http://ellislab.com/codeigniter/user-guide/helpers/download_helper.html


Download File Bug: weird characters ! - El Forum - 05-14-2009

[eluser]yannyannyann[/eluser]
Indeed, I am using this method :

How to force download

I still get the same error.

to see it in action, go here to my site which has the bug and click in the sidebar on a wallpaper (NO SPAM, NO POPUP I promise)

I have this error with different MIME TYPES : mp3, jpg, mpg, flv, ....

THey were all working before! What could have happened ?


Download File Bug: weird characters ! - El Forum - 05-14-2009

[eluser]TheFuzzy0ne[/eluser]
My guess is that you're sending something out before the header is sent, be it a whitespace or something along those lines.


Download File Bug: weird characters ! - El Forum - 05-14-2009

[eluser]yannyannyann[/eluser]
As I didn't change the function :

Code:
function output_file($file, $name, $mime_type='')

wich is containing the headers, I do'nt know how I could get characters sent before :S


Download File Bug: weird characters ! - El Forum - 05-14-2009

[eluser]davidbehler[/eluser]
a simple
Code:
echo "some character";
or a whitespace before the <?php could be enough.

Firefox says the type of the content on your download site is "text/html"...sure you are sending the headers?


Download File Bug: weird characters ! - El Forum - 05-14-2009

[eluser]Dam1an[/eluser]
If you have any whitespace in your PHP files outside the <?php and ?> tags, it gets sent to the browser
Also, you might have an acho statement in your code somewhere?


Download File Bug: weird characters ! - El Forum - 05-20-2009

[eluser]yannyannyann[/eluser]
It happened to be that accidentally loaded another file in my download controler.
I don't remember how this code came here :-)

So in the end all good !

Thank you guys !