For example, users send a post to upload a picture (the file is stored in seven cattle such a third-party platform, the user uploads the success of the database will write a record), when the user upload the picture, the user suddenly do not want to post, directly turned off the browser. The result is that the image that the user just uploaded becomes garbage.
Excuse me, how do I set the database logic, when the user uploaded files are not used, the background directly erased files
Reply content:
For example, users send a post to upload a picture (the file is stored in seven cattle such a third-party platform, the user uploads the success of the database will write a record), when the user upload the picture, the user suddenly do not want to post, directly turned off the browser. The result is that the image that the user just uploaded becomes garbage.
Excuse me, how do I set the database logic, when the user uploaded files are not used, the background directly erased files
I can't see it anymore,
Say the way, regardless of the last post, will upload the corresponding image ID to the database, just the corresponding post ID of the picture is empty or 0, the query is one hour from the current time (the time itself), if there is no corresponding to think he trash pictures, call Seven cow interface Delete, delete database records
If you post it, mark the corresponding Post ID
A lot of ah, personally think the most simple hair is, before the success of the post, the picture to save temporary folder, or to do temporary file identification, post success before the picture moved to the appropriate folders or remove temporary file identification, so that the timing to delete temporary files on the good,
Do not use the database to save the file, the following directory to save files, such as the form form upload file Upload files will be saved in the system temporary directory, after the general will be moved to the Web file directory, so you can be divided into a directory as a permanent directory, for the saved files moved to the permanent directory, The temp directory is timed clean-up OK. For the data inventory file, form upload will still remain in the system temporary directory, you can move the file to a temporary storage table or temporary directory, keep the successful move to the Permanent storage table/directory, and then periodically clean up the temporary table/directory. So you actually have 3 places to store: System temp directory, temp directory/temporary table, Permanent directory/Permanent table, then the easiest way is to only use the system temp directory + Permanent directory/Permanent table, the last file in the system temporary directory, only record a path, keep moving to permanent directory/Permanent table, not save the scheduled cleanup.
In fact, the PHP uploaded files are saved to the system temp directory at the beginning. It would be nice if you didn't move it.
Or you need:
Http://php.net/manual/zh/function.tempna ...
This function generates a temporary file that can be used when the directory is in the pro system.
Seven cattle official multimedia static resources processing or recommend the use of JS SDK upload, can reduce server-side processing, only need to remember the file upload a few basic information can, very convenient, performance is also the best choice at present. Security do not worry, please refer to the documentation, and do a good job of JS cross-domain control. Attention to the "phpgod"php technology Daquan, the achievement of the great God is not far.