Wednesday, October 30, 2013

Generate .csv file using PHP

<?php
           // Set label with comma separated
            $str='';
            $str.="tracking_name,origin_zipcode,destination_zipcode,price,customername,orderid,
                       alt_email_id";
            $str .="\n";
          // Set value with comma separated
            $str .="BR76646474RT,5874,2564,150,jaoun brend,ID6353653,admin@admin.com";
            $str .="\n";
            $str .="BR76646474RT,5874,2564,150,jaoun brend,ID6353653,admin@admin.com";
         
          // Set header for download file
            header("Expires: 0");
            header("Cache-control: private");
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header("Content-Description: File Transfer");
            header("Content-Type: application/vnd.ms-excel");
            header("Content-type: text/x-csv");
            header("Content-Disposition: attachment; filename=rastreamento_detalhado.csv");
            print $str;
            exit;
?>


No comments:

Post a Comment