WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 7 months ago

#49907 new defect (bug)

CSV Download issue after version update to v5.4

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

Description

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');
ob_end_clean();
$ptp_id = $_GET['topic'];
$pct_nm = $_GET['center'];
if(!empty($pct_nm))
$query = 'select * from wp_refresher_tracker where post_id ='.$ptp_id.' and centre_name = "'.$pct_nm.'"';
else
$query = 'select * from wp_refresher_tracker where post_id ='.$ptp_id;
//echo $query;
$presult = $wpdb->get_results($query);
//print_r($presult);
// 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){
$cnt=$cnt+1;
$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;; 
//print_r($refdata);
fputcsv($output, $refdata);
}
fclose($output);
exit;
}}?>

Change History (1)

#1 @SergeyBiryukov
7 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/.

Note: See TracTickets for help on using tickets.