Question: php script to delete file names not matching a dynamic text file
I have created a text file (images.txt) located in /home/users/images.txt, php error the File contain names of jpeg files. for example:
1.jpeg
12.jpeg
33.jpeg
This file is updated regularly and new image filenames are added
I am looking for a php script that can help in reading the filenames from the .txt and deleting any files from /home/user/images/ directory that does php error not match the filenames in the .txt file
I have tried the below code and cant get it to work
$array = explode("\n", file_get_contents('/home/user/images.txt')); $directory = "/home/user/images/"; $files = glob($directory . "*.*"); foreach($files as $file) { if (!in_array($file, $array)) { unlink($directory . $file); } }
9codings