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

How to implement file download function in laravel?

WBOY
Release: 2016-08-26 10:28:26
Original
2024 people have browsed it

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template