Nothing is wrong this is completely expected behavior.
You set $file->owner_guid to $user->owner_guid thus the file contents gets saved there. When generating icons we try to keep them with the entity the icons relate to. In this case the $file.
You can use the \ElggFile to store information on disk and while doing that the \ElggFile doesn't need to have a guid yet, same as in your example. You created the \ElggFile wrote some data to disk and than saved it. Before the save there was no GUID for the \ElggFile. You also can't make the \ElggFile the owner of itself this can cause lots of problems.
ps: always try to mention which Elgg version you're using, this can help others give the correct advice/solution
If it's just a matter of renaming, I recommend this must-have plugin.
Use the release for Elgg version you're running.
Just look for the Elgg tab in the "Recommended Releases" section when downloading the plugin.
1 - Download My plugin (Currently only available for Elgg 5, but I will release a version for Elgg 6 in a few hours.)
2 - Open \my_plugin\elgg-plugin.php and after
'bootstrap' => \MyPlugin\Bootstrap::class, // for more options
add this section:
'actions' => [
'discussion/save' => [
'access' => 'admin',
],
'file/upload' => [
'access' => 'admin',
],
],
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.