PHP laravel realizes file download function

Last lts of laravel (long term support) the version is laravel 5.1, which was released in June 2015. According to the agreement on the LTS version, the two-year bug repair support will end by the middle of this year. Therefore, a successor version of LTS, laravel 5.5, is bound to be released in the middle of this year. This article focuses on the implementation method of laravel's file download function. Please refer to this article

The download method can be used to generate a response that forces the user's browser to download a file with a specified path. The download method takes the file name as the second parameter of the method, which is the file name seen by the user when downloading the file. Finally, you can pass an array containing HTTP header information into the method as the third parameter:

The following is the file download function I used in the project.

However, at the beginning, the progress was not very smooth. Why did you fail to use the file download function of laravel? The error is as follows:

The general meaning is that the header () method has not been defined. After various explorations, we have found a solution. We can redefine the header and add the following methods to the handle method of corsmiddleware:

Finally, after redefining the header, we found that it can be accessed normally after using the download function.

summary

The above is what Xiaobian introduced to you. PHP laravel realizes the file download function. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>