Fixed php7.1; ErrorException: tempnam(): file created in the system's temporary directory


Well-known member
If you are stream wrappers; php7.1 starts throwing "tempnam(): file created in the system's temporary directory" on avatar or attachment uploads. This is because tempnam() deosn't actaully support stream wrappers.

Previous versions would silently use the system temporary directory, and as such would work as expected.

The problem is XenForo_Helper_File::getTempDir is defined as:
 public static function getTempDir()
  return self::getInternalDataPath() . '/temp';
Rather than something that can be defined independantly of the internal data path which can be in a path defined by a stream wrapper.

This affects;
  • avatar uploading on registration (gravatars)
  • attachments
  • avatar uploading
  • various importers
I think this affects:
  • XenForo's HTTP client (image proxy + title auto-link)
Last edited:


Well-known member
I think a safeTempnam() will be created like there is a safeRename() will be requires since there is a bit of logic that needs fixing around it.


XenForo developer
Staff member
Given that we're talking about a temp file, I don't think there's any disadvantage to using sys_get_temp_dir in getTempDir if your internal_data path is a stream wrapper (matches 'protocol://'). Beyond the tempnam usage, I'm not sure you'd necessarily be wanting to actually create a temp file in (say) S3 and clearly that has just silently fallen back to the system temp dir previously so this shouldn't really be behaving any differently with this change.