There is such a workaround on the development documentation.
The principle is to generate a download response that is automatically downloaded when the route is accessed, but the route is fixed. And the files are fixed. Now you want to implement this feature. In a controller, write the file into the demo.txt under public. Then download Demo.txt to Local.
Found that this can only be obtained in response. However, it cannot be downloaded.
。 How to implement the download function? Because the downloaded files are generated on the fly, the development documentation above says that download generates a fixed route response to download events is inappropriate.
Reply content:
There is such a workaround on the development documentation.
The principle is to generate a download response that is automatically downloaded when the route is accessed, but the route is fixed. And the files are fixed. Now you want to implement this feature. In a controller, write the file into the demo.txt under public. Then download Demo.txt to Local.
Found that this can only be obtained in response. However, it cannot be downloaded.
。 How to implement the download function? Because the downloaded files are generated on the fly, the development documentation above says that download generates a fixed route response to download events is inappropriate.
Direct output binary stream.
To output the response header
header('Content-Type: plain/text')