Use $isfile, not $exists reason is, if I create a folder named $nick $+ .txt, $exists will return true, but it's not a file, it is a folder. $isfile only returns true if it is a file, it will return false if it either doesn't exist or is a folder.