How can I process a temporary image uploaded during a user posting?

Source: Internet
Author: User
For example, a user must upload an image before sending a post (the file is stored on a third-party platform such as qiniu, and a record will be written into the database after the user uploads the post ), when the user uploads an image, the user suddenly does not want to post it, and directly closes the browser. The result is that the image you just uploaded is... for example, a user must upload an image before sending a post (the file is stored on a third-party platform such as qiniu, and a record will be written into the database after the user uploads the post ), when the user uploads an image, the user suddenly does not want to post it, and directly closes the browser. As a result, the uploaded image becomes junk.
How can I set the database logic? When the File Uploaded by the user is not used, the background will directly clear the file

Reply content:

For example, a user must upload an image before sending a post (the file is stored on a third-party platform such as qiniu, and a record will be written into the database after the user uploads the post ), when the user uploads an image, the user suddenly does not want to post it, and directly closes the browser. As a result, the uploaded image becomes junk.
How can I set the database logic? When the File Uploaded by the user is not used, the background will directly clear the file

I can't stand it anymore,

Let's talk about it. No matter whether the post is sent or not, the id of the uploaded image is saved to the database, but the id of the corresponding post of the image is null or 0, the query is one hour away from the current time (determined by the time). If there is no corresponding junk image, the system considers it as a junk image and calls the qiniu interface to delete the database records.

If a post is posted, the corresponding post id is marked.

There are many ways to do this. I personally think the simplest method is to save a temporary file folder or mark a temporary file before the post is successfully posted, after the post is successful, move the image to the corresponding folder or remove the temporary file ID. In this way, you can delete the temporary file regularly,

If files are not saved in the database, the files are saved in the directory. For example, after the form is uploaded, the files are saved in the temporary directory of the system and then moved to the file directory on the Web, therefore, you can use another directory as a permanent directory. If you want to save the file and move it to a permanent directory, you can clear the temporary directory regularly. For data inventory files, after the form is uploaded, it will still be stored in the temporary directory of the system. You can move the files to a temporary storage table or temporary directory, and then move them to the permanent storage table/directory, regularly clear the temporary tables/directories. In this way, you actually have three places for storage: temporary directory of the system, temporary directory/temporary table, permanent directory/Permanent Table, the easy-to-use method is to only use the temporary directory + permanent directory/Permanent Table of the system. After the last time, the file is in the temporary directory of the system, only a path is recorded, and then moved to the permanent directory/Permanent Table, do not save the timed cleanup.

In fact, the files uploaded by php are saved to the temporary directory of the system at the beginning. You just need to leave it alone.

Or you need:
Http://php.net/manual/zh/function.tempna...
This function will generate a temporary file that can be used in the directory when it comes to the system.

We recommend that you use the js sdk to upload official multimedia static resources of qiniu to reduce server processing. You only need to remember the basic information after the file is uploaded, which is very easy to handle, performance is also the best choice. You don't have to worry about security. Please refer to the documentation and complete js cross-origin control. Follow the "phpgod" PHP Technology book, which is far from achieving great success.

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.