php - using glob to delete image files along with corresponding db row -


I am using the following as the 'Delete all' option for users, the user has the thumbnail of every image Together they have images in their account, each image has a similar line in the database.

This works, I am worried that during the execution of this script new images can be uploaded with new lines in 'DB'.

So say that large amounts of images are now being removed ... all the images have been removed in the loop first ... Now perhaps new images have been added during this ... Now the thumbnails are removed when new thumbnails are removed, where the image was not deleted, the first pass. Finally, the rows in DB are removed ... the same thing ... new entries are removed and now there is an image and thumb which is not yet related entry in DB. Hope this makes sense.

Can I make sure that the same data has been removed from all the three functions?

  // Delete all screenshots before $ ss_files = glob ($ _ server) 'DOCUMENT_ROOT'] '/ .. / user's data /' .$_ session ['user'] ['ACCOUNT_ID / screenshot / *'). ']. '; Foreign exchange ($ ss_files $ ss_file) {if (is_file ($ ss_file)) {unlink ($ ss_file); // Delete the file}} // First remove all thumbnails $ ss_files = glob ($ _ SERVER ['DOCUMENT_ROOT']. '/ .. / user-data /'.$_ session [' user '] [' account_id '].' / Screenshot / thumbs / * '); Foreign exchange ($ ss_files $ ss_file) {if (is_file ($ ss_file)) {unlink ($ ss_file); // file delete}} // create stmt $ stmt = $ db- & gt; Add users ("DELETE del_table. *) As users of users on the del_table INNER as images_logs. User_id = del_table.user_id join computers on INNER computers on computersUPDirect_ID = Users Computer_id WHERE computer.account_id =: account_id"); // Add binding and $ binding = execute the array ('account_id' = & gt; $ _SESSION ['user'] ['account_id']); $ Stmt- & gt; Execution ($ binding);  

The fact that I'm worried about is the fact that uploading new images Can be done, along with the new script being added to 'DB' during the execution of this script.

Your current view is not good First of all, if you expect to take more time, you should first present the "deleted" flag in such a case. E. If you want to delete the image, then you mark it in the DB as deleted (even if you need to do more cleaning for the user account) and that's it. done. Deleted Found some related data to physically remove? Create a separate "garbage collector" that will remove the files and clear "deleted" records from DB and run by the cron. In such an approach, the process of removal is early, it can take more time to be saved, but this is not a problem.

In addition, you should not have to recreate files at the first place, but DB is more important than DB record data. / P>


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -