-1

I use download helper in codeigneter,, when i download file jpeg and open it,, it becomes invalid...

What should i do..

Thank you...

Controller

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

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

}

View

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

1 回答 1

1

我遇到了同样的问题,我用其他方法修复了它......如果你仍然想要它

$file_name = "picture.jpg" 
$file_path = "your path" 
header('Content-Type: application/octet-stream'); 
header("Content-Disposition: attachment; filename=$file_name");
ob_clean(); flush(); 
readfile($file_path);
于 2014-01-13T21:37:55.567 回答