<?php
include("../script/php/konecta.php");

$name = 'Reporte';  
$nombreArchivo="aptitudacad";
$fechadescarga=date("YmdHis");

header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename=test.csv');  
header('Expires: 0');  
header('Cache-Control: no-cache'); 


$row=array();
$sql = "SELECT * FROM exmaptituacadxxi";
if ($result = $nuevakonex->query($sql)) {
    //echo "\xEF\xBB\xBF";    
    $stream = fopen('php://output', 'w');
    // Poner titulos
        $row['nombres']  = "nombres";
        $row['apellidos']  = "apellidos";
        $row['sudni']  = "sudni";
        $row['sucelular']  = "sucelular";
        $row['sucorreo']  = "sucorreo";
        $row['carrera']  = "carrera";
        $row['check1']  = "check1";
        $row['fecha']  = "fecha";
        fputcsv($stream, array($row['nombres'], $row['apellidos'], $row['sudni'], $row['sucelular'], $row['sucorreo'], $row['carrera'], $row['check1'], $row['fecha']),';');

    while($field = $result->fetch_object()){
        // Llenar datos
        $row['nombres']  = $field->nombres;
        $row['apellidos']  = $field->apellidos;
        $row['sudni']  = $field->sudni;
        $row['sucelular']  = $field->sucelular;
        $row['sucorreo']  = $field->sucorreo;
        $row['carrera']  = $field->carrera;
        $row['check1']  = $field->check1;
        $row['fecha']  = $field->fecha;
        fputcsv($stream, array($row['nombres'], $row['apellidos'], $row['sudni'], $row['sucelular'], $row['sucorreo'], $row['carrera'], $row['check1'], $row['fecha']),';');
    }   
    $streamSize = ob_get_length(); 
    fclose($stream);
	header('Content-Length: '.$streamSize);
}
$result->close();
?>