Hello.
I'm trying to create a file not from the local storage:
$temp = new \ElggTempFile();
$temp->open('write');
$temp->write($content);
$temp->close();
$file = new \ElggFile();
$file->owner_guid = $user->owner_guid;
$file->container_guid = $user->guid;
$file->access_id = $user->access_id;
$filename = elgg_strtolower('file/' . time() . 'file.jpg');
$file->setFilename($filename);
$file->filestore_prefix = 'file';
$file->open('write');
$file->write($content);
$file->close();
$file->originalfilename = 'file.jpg';
$file->title = 'file.jpg';
$mime_type = _elgg_services()->mimetype->getMimeType($file->getFilenameOnFilestore());
$file->setMimeType($mime_type);
$file->simpletype = _elgg_services()->mimetype->getSimpleType($mime_type);
if (!$file->save()) {
$file->delete();
$temp->delete();
} else {
$file->saveIconFromElggFile($temp);
$temp->delete();
}
/data/1/40/file/file.jpg
/data/1/1090/icons/icon/master.jpg
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.
- Jerome Bakker@jeabakker
Jerome Bakker - 1 like
- maxvin@maxvin
maxvin - 0 likes
- iionly@iionly
iionly - 1 like
- maxvin@maxvin
maxvin - 0 likes
You must log in to post replies.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
Thanks for your reply.
Unfortunately, nothing helped.
I tried to do this:
There was a typo in the previous example not $user->owner_guid but $user->guid.
But that didn't help either.
I'm using Elgg 5.1.9
As Jerome said, setting
is the reason.
Have you tried NOT setting owner_guid at all?
It also seems you're not setting container_guid in the code of your latest post. I guess you could still set
to preserve the owner information after omitting to set owner_guid.
Thanks, iionly.
I tried doing this with different variations of the code.
For example, this one:
But the file is still saved in the logged in user's folder, but not under its own GUID