Welcome Guest, Not a member yet? Register   Sign In
delete all files not listed in db table
#1

[eluser]megabyte[/eluser]
Does anyone have a method they use they'd wanna share?

I'm thinking creating two arrays.

One of the list of files, the other the directory contents.

Then compare the two arrays?

Pro's/ Con's, faster safer way?
#2

[eluser]JoostV[/eluser]
If you use a key=>value pair array for the files from the DB, you can loop through all files and check if they are in that array
Code:
if(!in_array($file, $file_array)) {
    // Unlink the file
}

You array would have to be like
Code:
$file_array = array('file1.jpg', 'file2.jpg');

When you loop through the folder contents, be careful to unlink only files, not folders or empty values Wink




Theme © iAndrew 2016 - Forum software by © MyBB