0

In laravel 5.7 app I need to write csv file and download in in browsers download function using method :

\Response::download(

I try to upload it to tmp directory and checking value I see

$sys_get_temp_dir= sys_get_temp_dir(); 

line above has /tmp value

Next I save it as :

$dest_csv_file= $sys_get_temp_dir . '/box_rooms_'.time().'.csv'; $header = ["Id",... ]; $fp = fopen($dest_csv_file, "w"); fputcsv($fp, $header); foreach ($storageSpacesCollection as $line) { fputcsv($fp, $line); } fclose($fp); 

But searching on my local ubuntu 18(on server I also have ubuntu) I found generated file as

/tmp/systemd-private-6a9ea6844b9c4c94883d23e4fb3e2215-apache2.service-shqCeo/tmp/box_rooms_1576324869.csv 

That was very strange, as I do not know how read it from tmp path. Can it be done?

1 Answer 1

1

I think you need to pass Content-Type properly

$filePath= public_path(). "/upload/example.doc"; $headersContent = array('Content-Type: application/pdf',); return Response::download($filePath, 'example.doc', $headersContent) 
Sign up to request clarification or add additional context in comments.

1 Comment

A little explanation of what was wrong and what you changed to make it work would be nice

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.