문제

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