You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2024-08-30 08:56:49

nmy
Member
Registered: 2014-02-18
Posts: 13

Export To CSV issue

Hello,

I'm writing a simple glpi plugin and I try to send the data as file through the browser....

ob_start();
     
      header('Content-Type: text/csv; charset=utf-8');
      header('Content-Disposition: attachment; filename=csv_export.csv');
     
      $header_args = array( 'ID', 'Name', 'Email' );
     
      $data = array(
         array('1', 'Test 1', 'test1@test.com'),
         array('2', 'Test 2', 'test2@test.com'),
         array('3', 'Test 3', 'test3@test.com'),
      );

      ob_end_clean();

      $output = fopen( 'php://output', 'w' );

      fputcsv( $output, $header_args );

      foreach( $data as $data_item ){
         fputcsv( $output, $data_item );
      }

      fclose( $output );
      exit;


isn't working at all, the only thing I have is the content of data on the page.

Someone can help me?

Regards,

Offline

#2 2024-08-31 12:43:14

cconard96
Moderator
Registered: 2018-07-31
Posts: 2,809
Website

Re: Export To CSV issue

Why are you buffering the output, which in this case contains only your headers, and then disregarding it?


GLPI Collaborator and Plugin Developer.
My non-English comments are automated translations. Sorry for any confusion that causes.
Mes commentaires non anglais sont des traductions automatiques. Désolé pour toute confusion qui cause.
Mis comentarios que no están en inglés son traducciones automáticas. Perdón por cualquier confusión que cause.

Offline

Board footer

Powered by FluxBB