Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem exporting data to csv file

    Hi all,

    this is the code i'm using at the moment which is at the bottom of a webpage

    PHP Code:
    // Open file export.csv.
    $f fopen("export.csv""w");

    // Put all values from $out to export.csv.
    fputs($f$out);
    fclose($f);

    $filename "StatisticalAnalysis-" gmdate("Y-m-d-H-i-s") . ".csv";

    header("Content-type: application/csv");
    header("Content-Disposition: attachment; filename=" $filename);
    readfile("export.csv"); 
    The variable named $out is a long line of text in csv format. I've echoed that variable and the code is all good.

    When a checkbox in a form further up the page is checked the code creates and fills in the $out variable and then carries out the code above.

    The problem i have is that when the csv save dialog comes up and the file is saved, all it contains is a copy of the html code which is on that page, not the info stored in the $out variable.

    Can anyone offer any advice on what the problem is?

    Cheers

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,348
    Thanks
    23
    Thanked 618 Times in 617 Posts
    The question is where did you echo the $out? Just after you set the variable or just before you wrote to the file. You should do both to see if $out is being changed.

  • #3
    New Coder
    Join Date
    Aug 2011
    Location
    Melbourne, Brighton 3186
    Posts
    17
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Yes, show the code for the bit where you create the content for $out and it might come clear?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •