H
H
HitGirl2021-02-09 10:03:06
PHP
HitGirl, 2021-02-09 10:03:06

How to remove unwanted images uploaded with TinyMCE5?

Hello!
When I insert an image into the input field, it is immediately uploaded to the server in the upload folder (so that there is no repetition of names, I add the current time to the image name). But if I then remove the images from the input field, it remains in the folder. Also, when you rotate an image, a new image is loaded each time, although only the final image is used. Can you please tell me how to detect and delete unused images so that they do not take up space on the server?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2021-02-09
@HitGirl

The simple answer is no. That is, there are no normal, universal options.
Options with crutches:
0) in any case, the body of your text will need to be checked with a regular expression and pull out all the paths to the images uploaded to your server.
1) When loading, indicate the record identifier in the file name, and when saving, check accordingly all files with this identifier for a match with those in the text, delete unnecessary ones. The option is not very convenient, since when you first save the identifier, it may not yet be there.
2) When loading in the session, store all the paths to the downloaded files, when saving, check the lists, delete the excess, clear the session.
3) Clean with your hands through some kind of file manager, try not to upload a lot of garbage.
In general, there are no particularly "good" solutions with this approach to loading, they all require at least text parsing, which in itself is not a very beautiful solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question