7 use Symfony\Component\HttpFoundation\File\Exception\FileException;
8 use Symfony\Component\HttpFoundation\File\UploadedFile;
46 parent::initializeAttributes();
48 $this->attributes[
'subtype'] =
'file';
75 return parent::__get(
$name);
102 return ltrim(Paths::sanitize(
$filename,
false),
'/');
112 return $this->getFilestore()->getFilenameOnFilestore($this);
122 if ($this->mimetype) {
123 return $this->mimetype;
127 return _elgg_services()->mimetype->getMimeType($this->getFilenameOnFilestore());
128 }
catch (ElggInvalidArgumentException $e) {
144 $this->mimetype = $mimetype;
154 if (isset($this->simpletype)) {
155 return $this->simpletype;
158 return _elgg_services()->mimetype->getSimpleType($this->getMimeType() ?:
'');
172 if (!$this->getFilename()) {
173 throw new IOException(
'You must specify a name before opening a file.');
176 if (!in_array(
$mode, [
'read',
'write',
'append'])) {
177 throw new ElggDomainException(
"Unrecognized file mode '{$mode}'");
181 $this->handle = $this->getFilestore()->open($this,
$mode);
183 return $this->handle;
194 return $this->getFilestore()->write($this->handle,
$data);
206 return $this->getFilestore()->read($this->handle,
$length,
$offset);
215 return $this->getFilestore()->grabFile($this);
224 if (is_resource($this->handle) && $this->getFilestore()->close($this->handle)) {
225 $this->handle =
null;
236 public function delete(
bool $recursive =
true,
bool $persistent =
null):
bool {
238 return $this->persistentDelete($recursive);
249 $result = parent::persistentDelete($recursive);
251 $this->getFilestore()->delete($this);
257 return $this->getFilestore()->delete($this);
268 $this->getFilestore()->seek($this->handle,
$position);
277 return $this->getFilestore()->tell($this->handle);
286 $filestorename = $this->getFilenameOnFilestore();
288 $modified = touch($filestorename);
290 clearstatcache(
true, $filestorename);
292 elgg_log(
"Unable to update modified time for {$filestorename}", \Psr\Log\LogLevel::ERROR);
304 return filemtime($this->getFilenameOnFilestore());
314 return $this->getFilestore()->getFileSize($this);
322 public function eof(): bool {
323 return $this->getFilestore()->eof($this->handle);
332 return $this->getFilestore()->exists($this);
361 if (!$this->exists()) {
369 $filestorename = $this->getFilenameOnFilestore();
373 $this->open(
'write');
376 return rename($filestorename, $this->getFilenameOnFilestore());
396 if (!$upload->isValid()) {
400 $old_filestorename =
'';
401 if ($this->exists()) {
402 $old_filestorename = $this->getFilenameOnFilestore();
405 $originalfilename = $upload->getClientOriginalName();
406 $this->originalfilename = $originalfilename;
407 if (empty($this->title)) {
408 $this->title = htmlspecialchars($this->originalfilename, ENT_QUOTES,
'UTF-8');
411 $this->upload_time = time();
412 $prefix = $this->filestore_prefix ?:
'file';
413 $prefix = trim($prefix,
'/');
416 $this->filestore_prefix = $prefix;
424 if ($uploaded !==
true && $uploaded !==
false) {
425 $filestorename = $this->getFilenameOnFilestore();
427 $uploaded = $upload->move(pathinfo($filestorename, PATHINFO_DIRNAME), pathinfo($filestorename, PATHINFO_BASENAME));
428 }
catch (FileException $ex) {
435 if ($old_filestorename && $old_filestorename != $this->getFilenameOnFilestore()) {
437 unlink($old_filestorename);
442 $mime_type =
_elgg_services()->mimetype->getMimeType($this->getFilenameOnFilestore());
443 $this->setMimeType($mime_type);
444 $this->simpletype =
_elgg_services()->mimetype->getSimpleType($mime_type);
445 }
catch (ElggInvalidArgumentException $e) {
463 return array_diff(array_keys(get_object_vars($this)), [
492 $file_svc = new \
Elgg\FileService\File();
493 $file_svc->setFile($this);
498 $file_svc->setDisposition(
'attachment');
499 $file_svc->bindSession($use_cookie);
503 'use_cookie' => $use_cookie,
506 return _elgg_services()->events->triggerResults(
'download:url',
'file',
$params, $file_svc->getURL());
521 $file_svc = new \
Elgg\FileService\File();
522 $file_svc->setFile($this);
527 $file_svc->setDisposition(
'inline');
528 $file_svc->bindSession($use_cookie);
532 'use_cookie' => $use_cookie,
$mode
Configure site maintenance mode.
if(! $user||! $user->canDelete()) $name
$params
Saves global plugin settings.
return[ 'admin/delete_admin_notices'=>['access'=> 'admin'], 'admin/menu/save'=>['access'=> 'admin'], 'admin/plugins/activate'=>['access'=> 'admin'], 'admin/plugins/activate_all'=>['access'=> 'admin'], 'admin/plugins/deactivate'=>['access'=> 'admin'], 'admin/plugins/deactivate_all'=>['access'=> 'admin'], 'admin/plugins/set_priority'=>['access'=> 'admin'], 'admin/security/security_txt'=>['access'=> 'admin'], 'admin/security/settings'=>['access'=> 'admin'], 'admin/security/regenerate_site_secret'=>['access'=> 'admin'], 'admin/site/cache/invalidate'=>['access'=> 'admin'], 'admin/site/flush_cache'=>['access'=> 'admin'], 'admin/site/icons'=>['access'=> 'admin'], 'admin/site/set_maintenance_mode'=>['access'=> 'admin'], 'admin/site/set_robots'=>['access'=> 'admin'], 'admin/site/theme'=>['access'=> 'admin'], 'admin/site/unlock_upgrade'=>['access'=> 'admin'], 'admin/site/settings'=>['access'=> 'admin'], 'admin/upgrade'=>['access'=> 'admin'], 'admin/upgrade/reset'=>['access'=> 'admin'], 'admin/user/ban'=>['access'=> 'admin'], 'admin/user/bulk/ban'=>['access'=> 'admin'], 'admin/user/bulk/delete'=>['access'=> 'admin'], 'admin/user/bulk/unban'=>['access'=> 'admin'], 'admin/user/bulk/validate'=>['access'=> 'admin'], 'admin/user/change_email'=>['access'=> 'admin'], 'admin/user/delete'=>['access'=> 'admin'], 'admin/user/login_as'=>['access'=> 'admin'], 'admin/user/logout_as'=>[], 'admin/user/makeadmin'=>['access'=> 'admin'], 'admin/user/resetpassword'=>['access'=> 'admin'], 'admin/user/removeadmin'=>['access'=> 'admin'], 'admin/user/unban'=>['access'=> 'admin'], 'admin/user/validate'=>['access'=> 'admin'], 'annotation/delete'=>[], 'avatar/upload'=>[], 'comment/save'=>[], 'diagnostics/download'=>['access'=> 'admin'], 'entity/chooserestoredestination'=>[], 'entity/delete'=>[], 'entity/mute'=>[], 'entity/restore'=>[], 'entity/subscribe'=>[], 'entity/trash'=>[], 'entity/unmute'=>[], 'entity/unsubscribe'=>[], 'login'=>['access'=> 'logged_out'], 'logout'=>[], 'notifications/mute'=>['access'=> 'public'], 'plugins/settings/remove'=>['access'=> 'admin'], 'plugins/settings/save'=>['access'=> 'admin'], 'plugins/usersettings/save'=>[], 'register'=>['access'=> 'logged_out', 'middleware'=>[\Elgg\Router\Middleware\RegistrationAllowedGatekeeper::class,],], 'river/delete'=>[], 'settings/notifications'=>[], 'settings/notifications/subscriptions'=>[], 'user/changepassword'=>['access'=> 'public'], 'user/requestnewpassword'=>['access'=> 'public'], 'useradd'=>['access'=> 'admin'], 'usersettings/save'=>[], 'widgets/add'=>[], 'widgets/delete'=>[], 'widgets/move'=>[], 'widgets/save'=>[],]
if(! $entity instanceof \ElggUser) $data
initializeAttributes()
Set subtype to 'file'.
getSize()
Return the size of the file in bytes.
acceptUploadedFile(UploadedFile $upload)
Writes contents of the uploaded file to an instance of ElggFile.
open(string $mode)
Open the file with the given mode.
grabFile()
Gets the full contents of this file.
setFilename(string $filename)
Set the filename of this file.
persistentDelete(bool $recursive=true)
{Permanently delete the entity from the database.If true (default) then all entities which are owned ...
getFilenameOnFilestore()
Return the filename of this file as it is/will be stored on the filestore, which may be different to ...
getModifiedTime()
Returns file modification time.
__sleep()
Get property names to serialize.
write(string $data)
Write data.
getSimpleType()
Get the simple type of the file.
exists()
Returns if the file exists.
getMimeType()
Get the mime type of the file.
__get($name)
Get an attribute or metadata value.If the name matches an attribute, the attribute is returned....
__set($name, $value)
Set an attribute or metadata value for this entity.Anything that is not an attribute is saved as meta...
setMimeType(string $mimetype)
Set the mime type of the file.
getInlineURL(bool $use_cookie=false, string $expires='')
Returns file's URL for inline display Suitable for displaying cacheable resources,...
read(int $length, int $offset=0)
Read data.
getFilestore()
Return the system filestore based on dataroot.
getFilename()
Return the filename.
setModifiedTime()
Updates modification time of the file and clears stats cache for the file.
transfer(int $owner_guid, ?string $filename=null)
Transfer a file to a new owner and sets a new filename, copies file contents to a new location.
canDownload(int $user_guid=0, bool $default=true)
Checks the download permissions for the file.
seek(int $position)
Seek a position in the file.
eof()
Return a boolean value whether the file handle is at the end of the file.
getDownloadURL(bool $use_cookie=true, string $expires='+2 hours')
Returns file's download URL.
close()
Close the file and commit changes.
tell()
Return the current position of the file.
Exception thrown if a value does not adhere to a defined valid data domain.
An IO Exception, throw when an IO Exception occurs.
Exception thrown if an argument is not of the expected type.
Find Elgg and project paths.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
_elgg_services()
Get the global service provider.
elgg_strtolower()
Wrapper function for mb_strtolower().
if(! $item instanceof \ElggEntity) $length
if(parse_url(elgg_get_site_url(), PHP_URL_PATH) !=='/') if(file_exists(elgg_get_root_path() . 'robots.txt'))
Set robots.txt.