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 7765925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:17:06+00:00 2026-06-01T15:17:06+00:00

I am trying to serve up a dynamically generated csv file. For some reason

  • 0

I am trying to serve up a dynamically generated csv file. For some reason when I get the file, there are 18 empty rows preceding the data. I don’t have any space between the headers I define and the csv data I’m sending. If I write the data to a file on the server, it does not get these empty rows. However, if I write the file and then try to serve it to the user, the empty lines come back. So I’m wondering if perhaps I’ve messed up the headers, or if perhaps there is another issue I’m not thinking of:

function generate_csv($source_type, $include_unpublished = FALSE) {

   // retrieve data from DB
   ....

   // start up headers
   $csv_name = "$source_type-$data_set-csv_" . date('Y-m-d') . '.csv';
   header('Content-Type: text/x-comma-separated-values');
   header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
   header('Cache-Control: private', false); // required for certain browser
   header('Content-Disposition: attachment; filename="' . $csv_name . '"'); 

   // send csv data
   print $csv_data;

} //end function

Disclaimer: I asked this question at https://drupal.stackexchange.com/questions/27649/extra-empty-rows-when-serving-csv-file, but it dosn’t seem to be drupal-specific and there weren’t many ideas coming up over there..

  • 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-01T15:17:08+00:00Added an answer on June 1, 2026 at 3:17 pm

    It must be problem with files that you are including. Every whitespace more than one newline after php closing tag ?> is sent to the browser.

    Best solution is to get rid of this closing tags in every php file.

    Other option will be to remove only unnecessary new lines from them or to bufer output and disregard it before serving file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to stream dynamically generated data to a client over HTTP using
I'm trying to get the values of dynamically generated FileUpload controls that I add
I'm trying to use a dynamically generated fully-qualified table name in sql server 2008.
I am trying to serve a svg map using: <object data=map.svg type=image/svg+xml width=400 height=300>
I'm trying to serve a pdf file from a database in ASP.NET using an
Trying to get my server to serve my rails apps. I have a test
I'm trying to detect ?=randomString (e.g: ?=s123ver which is dynamically generated server side) in
I'm trying to get some li's inside a ul float to the left and
I'm trying to dynamically create a PDF (on the server) with some text on
I have a C# code behind file that gets dynamically generated HTML from a

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.