Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

346
Vistas
how to save PHPspreadsheet xlsx file on xampp server?

I am using PHPspreadsheet to create xlsx file on xampp. I want to run cron jobs in wordpress that will auto export some orders and save xlsx file on xampp server. I've successfully exported a file using $writer->save('php:\\output'); but this just ask user where to download file.

I want that cron job will save file without asking user. i.e wp-content/export/$filename

Headers:

        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="file.xls"');
        header('Cache-Control: max-age=0');

PHP:

$objWriter = new Xlsx($objX);
    
    ob_start();
    $objWriter->save('php://output');
    $xlsData = ob_get_contents();
    ob_end_clean();

    //returning response to javascript
    $response =  array(
        'file_name' =>'s.xlsx',
        'op' => 'ok',
        'file' => "data:application/vnd.ms-excel;base64,".base64_encode($xlsData),
        
    );
    die(json_encode($response));

Javascript

jQuery.ajax({

        url: ajaxurl,
        type: 'POST',
        dataType: 'json',
        data: {
            form_data :detail_info,
            action: 'frontend_action_without_file' // this is going to be used inside wordpress functions.php
        },
        
        error: function(error) {
            
        },
        success: function(response) {
            //console.log("Insert Success" + response.file);
        
        }
    }).done(function(data){
        var $a = jQuery("<a>");
        $a.attr("href",data.file);
        jQuery("body").append($a);
        $a.attr("download",data.file_name);
        $a[0].click();
    
    });
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to create another page and use a function to download a file from url (in this case your page that generates xlsx), example below.

private function downloadFile($url, $path)
{
    $newfname = $path;
    $file = fopen ($url, 'rb');
    if ($file) {
        $newf = fopen ($newfname, 'wb');
        if ($newf) {
            while(!feof($file)) {
                fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
            }
        }
    }
    if ($file) {
        fclose($file);
    }
    if ($newf) {
        fclose($newf);
    }
}

downloadFile('https://yoururl.com/generateXlsx.php', 'xlsx/file.xlsx');

after this just execute this shell

* 10 * * * php -f /home/dev/cronjobs/downloadfile.php

this command execute your code every day on 10am /home/dev/cronjobs/downloadfile.php is the file path.

ps. You can use https://crontab-generator.org/ to generate your shell's

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda