Problem when exporting to excel on the server

0

I have the following problem I have a file php that I export to excel and download it automatically but it only works for me locally, if I upload it to the server it just opens like any other page. What can it be?

<?php 
include_once 'clases/clase_pedidos.php';
    error_reporting(E_ALL ^ E_NOTICE);
   session_start();
   if (!isset($_SESSION["rut"]) || empty($_SESSION["rut"]) ||            $_SESSION["perfil"]==2) {
   header("location: login.php");
}

$obj= new Pedido();

        $obj->id_activo="si";
        $obj->id_venado=$_GET["id_venado"];
        $obj->fecha_1=$_GET["fecha_1"];
        $obj->fecha_2=$_GET["fecha_2"];
        $obj->fecha_venado1= $_GET["fecha_venado1"];
        $obj->fecha_venado2=$_GET["fecha_venado2"];
        $tabla=$obj->lista_compra_fecha();
        $obj->excel="si";
        $tabla_cliente=$obj->lista_cliente_fecha();
        date_default_timezone_set("America/Santiago");
        $fecha = date("Y-m-d ");
header('Pragma: public'); 
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past    
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); 
header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1 
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 
header('Pragma: no-cache'); 
header('Expires: 0'); 
header('Content-Transfer-Encoding: none'); 
header('Content-Type: application/vnd.ms-excel'); // This should work for IE & Opera 
header('Content-type: application/x-msexcel'); // This should work for the rest 
header('Content-Disposition: attachment;    filename="pedido_rango_fecha'.$fecha.'.xls"');
 ?>
    
asked by jose miguel jara 21.12.2016 в 00:12
source

1 answer

2

pull out some headers and I'll let them work here in case someone has the same problem

header('Content-Type: application/vnd.ms-excel'); 

header('Content-Disposition: attachment; filename="pedido_.xls");

header('Pragma: no-cache'); 

header('Expires: 0'); 
    
answered by 21.12.2016 в 00:40