Shouldn't use __DIR__ but instead use the path provided in settings, the file will not live in the document root and will not be web accessible.  Should change the variable name $fid, since it is no longer descriptive.