PHP CSV create then echo javascript redirect -


i creating csv file in php, no biggie there, , force downloading user, again no biggie there. problem coming across redirect portion. know cannot create file , push user , use php redirect afterwards, kills csv creation due http protocols. instead, doing javascript redirect follows:

echo '<script>'; echo '    window.location = "'.base_url().'link/'.$item_id.'"'; echo '</script>'; die; 

this works fine (it reloads page), portion above echoed gets added on csv file when downloaded. here php code creates csv , force downloads it:

fwrite($csv, $csv_data); fclose($csv);  header('content-type: application/vnd.ms-excel'); header('content-length: ' . strlen($csv_data)); header("content-disposition: attachment; filename=$file_name"); readfile($file_path); 

what missing in terms of not having <script> text getting appended csv?

thanks in advance.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -