Download .csv file problem

Discussion in 'PHP' started by php-lover, Jul 22, 2009.

  1. #1
    Hi guys,

    I'm writing a code to download the csv file from my website. It's work perfect but some time I click on the download button, it didn't pop up to download a CSV file but it's popup to download a .php file. Some time it's doesn't popup anything but it's display the html code on the screen. It's wild, I don't know what is going on.

    Is there anyone experienced this problem before.

    Here's my header:

      header('Content-Description: File Transfer');
            //header("Content-type: application/csv");
            header("Content-type: application/octet-stream");
            header('Content-Disposition: attachment; filename='.basename($fname));
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            header('Content-Length: ' . filesize($fname));
            ob_clean();
            flush();
        
            readfile($fname); 
    PHP:
    Much appreciated your help and ideas.

    Cheers.

    Nau
     
    php-lover, Jul 22, 2009 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    Could you post more of the php file? Thanks
     
    crath, Jul 22, 2009 IP