0

I am using the script below to create *.csv files. The output of lines 5 and 6 are correct. It is also including other information in lines 1-4 and 8-10. This information is from the header and footer of my page.

Any suggestions how to prevent this information from being included?

<?php
$csv_output .= $lang['klant'].';';
$i++;

$csv_output .= $lang['klant_ref'].';';
$i++;

$csv_output .= $lang['pos'].';';
$i++;

$csv_output .= $lang['aantal'].';';
$i++;

$csv_output .= $lang['dikte'].';';
$i++;

$csv_output .= $lang['kwaliteit'].';';
$i++;

$csv_output .= "\n";

for ($j = 0; $j <= $aantal_regels; $j++)
{
    $csv_output .= $klantnaam.';';
    $csv_output .= $klant_ref.';';
    $csv_output .= $posno[$j].';';
    $csv_output .= $aantal[$j].';';
    $csv_output .= $dikte[$j].';';
    $csv_output .= $kwaliteit[$j].';';
    $csv_output .= "\n";
}

$filename = $file;

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$lang['lijst_dxf']." ".$dossier_nr." ".$klantnaam." ".$klant_ref.".csv");

print $csv_output;
?>
3
  • Try to use this php.net/manual/en/function.fputcsv.php Commented Jun 21, 2018 at 10:08
  • 1
    You should use separate page to do this action. If required use query string to pass parameter on that page. The issue comes because HTML content are present in this page. Commented Jun 21, 2018 at 10:16
  • Yes, I was hoping for a different solution Kuldeep. Then I will go with a different page. Commented Jun 21, 2018 at 10:28

1 Answer 1

1

The problem in your $csv_output you need to delete the html content but here quick solution :

...$csv_output =str_replace(array('<link rel="stlesheet" type="text/css" href="includes/css/style.css"></script>','<style typ }</style>',"<div id='wrap'>",'<div class="footer_popup">','<img src="images/torza_logo_t.png"/>','</div></div>')
                    ,array('','','','','',''),$csv_output);
....$filename = $file;

header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$lang['lijst_dxf']." ".$dossier_nr." ".$klantnaam." ".$klant_ref.".csv");

print $csv_output;
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.