You need the filename and the timestamp as parameter.

If the parameter is Null you can do the check like you did it below. If a timestamp is provided you need to check for $filename.'.d'.$timestamp

The reasons: Files in the top level view of the trash bin contain a timestamp, this allows to delete multiple files with the same name over the time. But file names within a deleted folder doesn't contain a timestamp.