Invalid image when using force download in codeigniter -
i use download helper in codeigneter,, when download file jpeg , open it,, becomes invalid...
what should 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() $row){ $hasil[]=$row; } return $hasil; } }
view
<table> <tr> <td>file upload</td> </tr> <?php foreach ($hasil $data) : ?> <tr> <td><a href="<?=base_url();?>main/downloadsuratelektronik/<?=$data->link_upload?>">/<?=$data->link_upload?></a></td> </tr> <?php endforeach; ?> </table>
i got same problem, fixed using other method... if u still want it
$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);
Comments
Post a Comment