Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8873043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:22:02+00:00 2026-06-14T18:22:02+00:00

I am trying to export CSV using PHP. But instead of printing the result

  • 0

I am trying to export CSV using PHP. But instead of printing the result it’s printing Resource id #26 in the generated CSV FILE. If I remove exit from end it print’s my whole HTML page content. My code is…

      if (isset($_REQUEST['download']) && ($_REQUEST['download'] == "yes")) {
            header('Content-Type: text/csv; charset=utf-8');
            header('Content-Disposition: attachment; filename=link_point_report.csv');
            $output = fopen('php://memory', 'w+');
            fputcsv($output, array('Member Id', 'Customer Name', 'Customer Email'));

            $customerListAll = $oAdmFun->linkpoint_check_customer('', '');       
             $oAdmFun->pr($customerListAll, true);
//                if (count($customerListAll) > 0) {
//                        for ($c = 0; $c < count($customerListAll); $c++) {
//                                fputcsv($output, array('Sankalp', 'Sankalp', 'Sankalp'));
//                        }
//                }

            ob_clean();
            flush();
            exit($output);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:22:03+00:00Added an answer on June 14, 2026 at 6:22 pm

    That’s because $output is a resource, which is what fopen() returns. You need to use fread() to get its contents.

    EDIT: Now I understand what you were asking. To output the contents of your CSV, you need to get the text output from the resource:

    rewind( $output );
    $csv_output = stream_get_contents( $output );
    fclose( $output );
    die( $csv_output );
    

    And it’s also a good idea to set the content-length header so that the client knows what to expect:

    header('Content-Length: ' . strlen($csv_output) );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to export some info from the database but when the CSV file
I have a PHP script that produces a .CSV export file from a MySQL
I'm trying to create a csv export of data from mysql using the following
I am trying to export some data from the console into a csv file
I have been trying to export the charts from Excel as an image file
I am trying to export the user from database, but its showing But if
I have a CSV export script (enrdata_arch.php) which calls information from an existing database
I am trying to generate a CSV file from DB Query as source one
I am trying to do 2 output data from mysql to a csv file.
I'm trying to export data to a csv file. It should contain a header

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.