0

I was wondering if someone could help me out.

I have some code which takes an array and puts it into csv format, at the moment, it saves the file to the server, but i want the user to be able to download the csv instead and nothing im trying is working.

Currently my function looks like this

public function postForm() {

    $exportType = Input::get('exportType');
    $data = Session::get('data');

    if ( $exportType == 'csv' ) {

        $fp = fopen('csvExport.csv', 'w');

        foreach( $data as $fields ) {
            fputcsv($fp, $fields);
        }

        fclose($fp);

    } else {

        // Other function here

    }

    return Response::json( array('result' => true) );

}

Can anyone help me out please, any help would be really greatly appreciated.

Cheers,

BigJobbies
  • 499
  • 8
  • 20

1 Answers1

1

If you want the user to download the file - you need to 'return' the file to them as the Response

 return Response::download('csvExport.csv');
Laurence
  • 58,936
  • 21
  • 171
  • 212