In the PHP script provided, what specific problem is encountered when trying to delete files from a directory based on database entries?

The specific problem encountered when trying to delete files from a directory based on database entries is the potential for orphaned files. This means that if a file is deleted from the database but not from the directory, it can lead to unused files taking up space. To solve this issue, we need to ensure that files are deleted from the directory whenever they are removed from the database.

// Get list of files from database
$files_from_db = ['file1.jpg', 'file2.jpg', 'file3.jpg'];

// Directory where files are stored
$directory = 'uploads/';

// Get list of files in the directory
$files_in_directory = scandir($directory);

// Delete files not present in the database
foreach ($files_in_directory as $file) {
    if ($file != '.' && $file != '..' && !in_array($file, $files_from_db)) {
        unlink($directory . $file);
    }
}