A
A
Andrey Ivanov2020-09-03 07:41:06
Node.js
Andrey Ivanov, 2020-09-03 07:41:06

What are the ways to delete a file from the server?

I am writing an admin. There is a function for uploading files.

I upload a file, write it to the database (name, size, id, src) I
use the id of the file where necessary

. To delete a file, I find it by id and delete it from the database, but not physically.
After some time, there will be more physical files on the disk than in the database.

Am I right in thinking that you need to write a script that will go through the files in the \uploads folder and compare the physical file name and the file name that is in the database, if the name does not match, then delete the file physically. Run this script once a day for example?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2020-09-03
@newdecline

congratulations: you have joined the slender ranks of crutch manufacturers.
The file should be deleted immediately when it is deleted from the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question