Laravel file download response content type is text/html in localhost

不问归期 提交于 2020-01-04 11:42:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!