How to generate a file in the PHPShell script and upload it to the server?

Source: Internet
Author: User
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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.