CodeIgniter Forums
Invalid or corrupt image when using force download in codeigniter - 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: Invalid or corrupt image when using force download in codeigniter (/showthread.php?tid=52288)



Invalid or corrupt image when using force download in codeigniter - El Forum - 06-05-2012

[eluser]beben[/eluser]
I use download helper in codeigneter,, when i download file jpeg and open it,, it becomes invalid or corrupt...

What should i do..

Thank you...

Controller
Code:
function downloadSuratElektronik($file)
{
    $this->load->helper('download');
    $file_data = file_get_contents(base_url()."data/".$file);
    $file_name = $file;
    force_download($file_name, $file_data);
}

Model
Code:
function getSuratKeluar(){
    $data = $this->db->get('surat_keluar');
    if ($data->num_rows() > 0){
        foreach ($data->result() as $row){
            $hasil[]=$row;
        }
        return $hasil;
}

View
Code:
<table>
    <tr>
    <td>File Upload</td>
    </tr>
    &lt;?php
    foreach ($hasil as $data) :
    ?&gt;
    <tr>
    <td><a href="&lt;?=base_url();?&gt;main/downloadSuratElektronik/&lt;?=$data-&gt;link_upload?&gt;">
    /&lt;?=$data->link_upload?&gt;</a></td>
    </tr>
    &lt;?php endforeach; ?&gt;
</table>



Invalid or corrupt image when using force download in codeigniter - El Forum - 06-05-2012

[eluser]WanWizard[/eluser]
Make sure zlib compression is disabled before you start the download.


Invalid or corrupt image when using force download in codeigniter - El Forum - 06-05-2012

[eluser]beben[/eluser]
[quote author="WanWizard" date="1338892443"]Make sure zlib compression is disabled before you start the download.[/quote]

What do you mean with zlib compression ?? sorry,, i'm still the newbie... thank you for your help...


Invalid or corrupt image when using force download in codeigniter - El Forum - 06-05-2012

[eluser]WanWizard[/eluser]
If you have enabled output compression, either in the CI config or in your php.ini, you need to disable it, as it will alter the data sent to the client.


Invalid or corrupt image when using force download in codeigniter - El Forum - 06-05-2012

[eluser]beben[/eluser]
i have disabled output compression in php.ini,, but nothing change...

but,, in ci config ?? how to setting it ?? i don't understand how to disabled output compression in ci.. thank you...