[wp-trac] [WordPress Trac] #49907: CSV Download issue after version update to v5.4

WordPress Trac noreply at wordpress.org
Tue Apr 14 19:29:07 UTC 2020


#49907: CSV Download issue after version update to v5.4
---------------------------------------------+-----------------------------
 Reporter:  amitdutt24                       |      Owner:  (none)
     Type:  defect (bug)                     |     Status:  new
 Priority:  normal                           |  Milestone:  Awaiting Review
Component:  General                          |    Version:  5.4
 Severity:  normal                           |   Keywords:
  Focuses:  accessibility, coding-standards  |
---------------------------------------------+-----------------------------
 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;
 }}?>
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49907>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list