I need to use a PHP script to generate a file (such as excel) and upload it to the server for users to download. Generally, when the file is not large, you can click Download on the page to fetch data from the database, set the heder header to output to the browser in the form of a stream, and set the file type for download... I need to use a PHP script to generate a file (such as excel) and upload it to the server for users to download.
Generally, when a file is not large, you can click Download on the page to fetch data from the database, set the heder header to output to the browser as a stream, and set the file type for download, this is certainly possible, but the problem is that it may be very large and time-consuming to generate a file now, so to make it asynchronous, the user clicks to download and enters a task into the queue, in the Shell script, read the queue task as a scheduled task, generate a file, and upload it to the server. How can this problem be solved?
I tried to create a temporary file in PHP and write the data to the temporary file. However, I found that the temporary file is of the resource type and cannot be uploaded through the last function. The function parameter must be a directory name, the imported information is resource-based.
Reply content:
I need to use a PHP script to generate a file (such as excel) and upload it to the server for users to download.
Generally, when a file is not large, you can click Download on the page to fetch data from the database, set the heder header to output to the browser as a stream, and set the file type for download, this is certainly possible, but the problem is that it may be very large and time-consuming to generate a file now, so to make it asynchronous, the user clicks to download and enters a task into the queue, in the Shell script, read the queue task as a scheduled task, generate a file, and upload it to the server. How can this problem be solved?
I tried to create a temporary file in PHP and write the data to the temporary file. However, I found that the temporary file is of the resource type and cannot be uploaded through the last function. The function parameter must be a directory name, the imported information is resource-based.
Why do I have to generate a temporary file, generate the file directly, upload the file, and delete the file after the upload is successful?