Вопрос

I'm creating a CSV from an array. The problem is that I dont want to download it but I want to save it to a folder in my server. This is my function

    protected function array_to_csv_download($array, $filename = "export.csv", $delimiter=";") {
    header('Content-Type: application/csv; charset=utf-8');
    header('Content-Disposition: attachement; filename="'.$filename.'";');

       $f = fopen('php://output', 'w');

    foreach ($array as $line) {
        fputcsv($f, $line, $delimiter); 
    }
} 

How can I make it so that it saves it to the server? Thanks!

Это было полезно?

Решение

  1. Remove headers.

  2. Use you server's file path in fopen handle.

$f = fopen('path of file on server ', 'w');
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top