samedi 26 août 2017

How to avoid csv file from getting saved in projects root folder

I was trying to export record as csv file on browser and it gets download in download folder, but while checking on live directory it also gets saved in projects root folder. I don't understand why.

Below is function code.

protected  function downloadcsv($fieldValue,$fieldArray,$from,$end){

        ob_clean();
        $data = $fieldValue->toArray(); 

        $filename = '';

        if($from === '' || $end === ''){

            $filename = "ExportOrders.csv";

        }else{

            $filename = "Orders-". $from ." to ". $end .'.csv';
        }
        $handle = fopen($filename, 'w+');

        fputcsv($handle,$fieldArray );

        foreach($data as $value) {

            fputcsv($handle, $value);
        }

        fclose($handle);

        $headers = array(
            'Content-Type' => 'text/csv',
        );

        return Response::download($filename,$filename, $headers);
}

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire