Laman

Report PHP CSV

 csv_download.php
<?php
for($i=1;$i<4;$i++){
    $out.="A,B,C,D,E,F\r\n"; 
}
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv".date("Y-m-d").".csv");
header("Content-disposition: filename=csv".date("Y-m-d").".csv");
print $out;
?>

csv_save_to_folder_server.php
<?php
$data_array = array (
            array ('1','2'),
            array ('2','2'),
            array ('3','6'),
            array ('4','2'),
            array ('6','5')
            );

$csv = "col1,col2 \n";//Column headers
foreach ($data_array as $record){
    $csv.= $record[0].','.$record[1]."\n"; //Append data to csv
}
//membuat file csv di folder server
for($i=1;$i<4;$i++){
    $csv_handler = fopen ("csv/csvfile".$i.".csv",'w');
    fwrite ($csv_handler,$csv);
    fclose ($csv_handler);
}
echo 'Data saved to csvfile.csv';
?>

No comments:

Post a Comment

Silahkan