Php导出到excel并同时显示到屏幕?

时间:2017-11-20 14:37:58

标签: php

我有这个代码来导出mysql select的结果,它运行得很好。但是,我需要在下载文件后在屏幕上显示一些信息。我将不胜感激任何帮助!!!

if ($results){
    function outputCSV($results) {
        $titulo = array('SMS_ID','ORIGEN','DESTINO','FECHA_ENTREGA','RESULTADO','CODIGO_ENTREGA','MENSAJE','TIPO_SMS');
        $outputBuffer = fopen("php://output", 'w');
        $first = true;
        fputcsv($outputBuffer, $titulo);
        foreach($results as $val) {
            fputcsv($outputBuffer, $val);
        }
        fclose($outputBuffer);
    }
    $filename = 'ConsultaMSISDN-TSE';
    header("Content-type: application/vnd.ms-excel");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Disposition: attachment; filename={$filename}.csv");
    header('Content-Transfer-Encoding: binary');
    header("Pragma: no-cache");
    header("Expires: 0");
    outputCSV($results);
    $conn->close();
    exit;
} else {
    print "<p align=\"CENTER\"><h1>Consulta no arrojó resultados.!</h1></p>";
    echo "<br><a href='panel-consultas_4-TSE-MSISDN.php'>Volver a Intentarlo</a>";
    $conn->close();
}

0 个答案:

没有答案