问题
I try to return file download response in laravel with custom content type, the response content type comes as text/html to browser in localhost. Whereas it works fine in the server machine code. It makes debugging harder.
Is it anything to do with apache server config?
Below is the laravel code used.
return Response::download($filepath, $filename.'_questionaire.csv', array(
'Content-Type' => 'text/csv',
'Content-Disposition' => 'attachment;filename="'.$filename.'._questionaire.csv"'
));
回答1:
To force your browser to download CSV files you can add this in the .htaccess file:
AddType application/octet-stream csv
You could also check out:
http://www.thingy-ma-jig.co.uk/blog/06-08-2007/force-a-pdf-to-download
回答2:
Add the below line to apache's httpd.conf in <IfModule mime_module>
block
AddType application/octet-stream .csv
回答3:
The above answers are not working any guess why... I added AddType application/octet-stream csv at the .htaccess file located at the site public folder @ mamp/htdocs/website/public but still no success
来源:https://stackoverflow.com/questions/19194154/laravel-file-download-response-content-type-is-text-html-in-localhost