Make WordPress Core

#49907 closed defect (bug) (invalid)

CSV Download issue after version update to v5.4

Reported by: amitdutt24 Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.4
Component: General Keywords: close reporter-feedback
Focuses: Cc:


My site was working fine with WordPress version 4.9.8 but after version update to 5.4 code to CSV Download has stopped working. In debug log showing warning Cannot modify header information - headers already sent .

Code to download CSV is as follows -

<?php if(isset($_GET['process'])){ 
if($_GET['process'] === 'download'){
global $wpdb;
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=refreshertracker.csv');
$ptp_id = $_GET['topic'];
$pct_nm = $_GET['center'];
$query = 'select * from wp_refresher_tracker where post_id ='.$ptp_id.' and centre_name = "'.$pct_nm.'"';
$query = 'select * from wp_refresher_tracker where post_id ='.$ptp_id;
//echo $query;
$presult = $wpdb->get_results($query);
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');

// output the column headings
fputcsv($output, array('Sr_no', 'Name', 'EID', 'Center', 'Topic', 'Brand', 'LOB', 'Skill', 'TrainerName', 'Obt_Marks', 'Total_Marks','Score_%', 'ETime','RefDate'));
$cnt = 0;
$refdata = array();
foreach($presult as $prt){
$refdata['Sr_no']= $cnt;
$refdata['Name']= $prt->name;
$refdata['EID']= $prt->eid;
$refdata['Center']= $prt->centre_name; 
$refdata['Topic']= $prt->topic; 
$refdata['Brand']= $prt->brand; 
$refdata['LOB']= $prt->lob; 
$refdata['Skill']= $prt->skill; 
$refdata['TrainerName']= $prt->trainer; 
$refdata['Obt_Marks']= $prt->obt_marks; 
$refdata['Total_Marks']= $prt->total_marks; 
$refdata['Score_%'] = round(($prt->obt_marks/$prt->total_marks)*100,2)." %";
$refdata['Time']= $prt->etime; 
$refdata['RefDate']= $prt->Post_Pub_Date;; 
fputcsv($output, $refdata);

Change History (2)

#1 @SergeyBiryukov
18 months ago

  • Focuses accessibility coding-standards removed
  • Keywords close reporter-feedback added

Hi there, welcome to WordPress Trac! Thanks for the report.

In debug log showing warning Cannot modify header information - headers already sent .

  1. Could you share the rest of the warning, where the file name and line number are specified?
  2. Could you provide the steps to reproduce the issue on a clean install?

Please note that this Trac is used for enhancements and bug reporting for the WordPress core software, not for individual support questions. Until the bug is identified and confirmed, please try the support forums for troubleshooting: https://wordpress.org/support/forums/.

#2 @hellofromTonya
10 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

I'm closing this ticket as it's been 8 months since reporter feedback was requested and marked as a close candidate. If this issue still exists, please provide feedback for further investigation.

Note: See TracTickets for help on using tickets.