Home >Backend Development >PHP Tutorial >How to implement file download function in laravel?

How to implement file download function in laravel?

WBOY
WBOYOriginal
2016-08-26 10:28:262016browse

There is such a solution in the development documentation.

How to implement file download function in laravel?The principle is to generate a download response and download it automatically when accessing this route, but this way the route is fixed. And the file is fixed. Now I want to implement this function. In a controller, write the file into demo.txt under public. Then download demo.txt to your local computer.

How to implement file download function in laravel?I found that this can only be obtained in response. But cannot download.
How to implement file download function in laravel?. How to implement the download function? Because the downloaded file is generated instantly, the method mentioned in the development document for download to generate a fixed route to respond to the download event is not appropriate.

Reply content:

There is such a solution in the development documentation.

How to implement file download function in laravel?The principle is to generate a download response and download it automatically when accessing this route, but this way the route is fixed. And the file is fixed. Now I want to implement this function. In a controller, write the file into demo.txt under public. Then download demo.txt to your local computer.

How to implement file download function in laravel?I found that this can only be obtained in response. But cannot download.
How to implement file download function in laravel?. How to implement the download function? Because the downloaded file is generated instantly, the method mentioned in the development document for download to generate a fixed route to respond to the download event is not appropriate.

Directly output binary stream.

To output the response header

<code>header('Content-Type: plain/text')</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn