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);
139 if ($this->mimetype) {
140 return $this->mimetype;
160 return $this->mimetype = $mimetype;
170 if (isset($this->simpletype)) {
171 return $this->simpletype;
189 throw new IOException(
'You must specify a name before opening a file.');
197 (
$mode !=
'write') &&
206 return $this->handle;
248 $this->handle = null;
263 public function delete($follow_symlinks =
true) {
301 $modified = touch($filestorename);
303 clearstatcache(
true, $filestorename);
305 elgg_log(
"Unable to update modified time for {$filestorename}",
'ERROR');
385 $this->
open(
'write');
408 if (!$upload->isValid()) {
412 $old_filestorename =
'';
417 $originalfilename = $upload->getClientOriginalName();
418 $this->originalfilename = $originalfilename;
419 if (empty($this->title)) {
420 $this->title = htmlspecialchars($this->originalfilename, ENT_QUOTES,
'UTF-8');
423 $this->upload_time = time();
424 $prefix = $this->filestore_prefix ?:
'file';
425 $prefix =
trim($prefix,
'/');
428 $this->filestore_prefix = $prefix;
435 $uploaded =
_elgg_services()->hooks->trigger(
'upload',
'file', $hook_params);
436 if ($uploaded !==
true && $uploaded !==
false) {
439 $uploaded = $upload->move(pathinfo($filestorename, PATHINFO_DIRNAME), pathinfo($filestorename, PATHINFO_BASENAME));
440 }
catch (FileException $ex) {
449 unlink($old_filestorename);
456 $this->simpletype =
_elgg_services()->mimetype->getSimpleType($mime_type);
474 return array_diff(array_keys(get_object_vars($this)), [
503 $file_svc = new \Elgg\FileService\File();
504 $file_svc->setFile($this);
505 if (!empty($expires)) {
506 $file_svc->setExpires($expires);
508 $file_svc->setDisposition(
'attachment');
509 $file_svc->bindSession($use_cookie);
529 $file_svc = new \Elgg\FileService\File();
530 $file_svc->setFile($this);
531 if (!empty($expires)) {
532 $file_svc->setExpires($expires);
534 $file_svc->setDisposition(
'inline');
535 $file_svc->bindSession($use_cookie);
getSize()
Return the size of the file in bytes.
$params
Saves global plugin settings.
$mode
Configure site maintenance mode.
An IO Exception, throw when an IO Exception occurs.
if(!$user||!$user->canDelete()) $name
if(!$item instanceof ElggEntity) $length
setModifiedTime()
Updates modification time of the file and clears stats cache for the file.
getFilestoreSize($prefix= '', $container_guid=0)
Return the size of the filestore associated with this file.
close()
Close the file and commit changes.
setFilename($filename)
Set the filename of this file.
seek($position)
Seek a position in the file.
eof()
Return a boolean value whether the file handle is at the end of the file.
exists()
Returns if the file exists.
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
getSimpleType()
Get the simple type of the file.
getGUID()
Returns the guid.
canDownload($user_guid=0, $default=true)
Checks the download permissions for the file.
elgg_strtolower()
Wrapper function for mb_strtolower().
getModifiedTime()
Returns file modification time.
getFilenameOnFilestore()
Return the filename of this file as it is/will be stored on the filestore, which may be different to ...
grabFile()
Gets the full contents of this file.
getFilestore()
Return the system filestore based on dataroot.
initializeAttributes()
Set subtype to 'file'.
setMimeType($mimetype)
Set the mime type of the file.
getFilename()
Return the filename.
read($length, $offset=0)
Read data.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
tell()
Return the current position of the file.
getDownloadURL($use_cookie=true, $expires= '+2 hours')
Returns file's download URL.
acceptUploadedFile(UploadedFile $upload)
Writes contents of the uploaded file to an instance of ElggFile.
getMimeType()
Get the mime type of the file.
getInlineURL($use_cookie=false, $expires= '')
Returns file's URL for inline display Suitable for displaying cacheable resources, such as user avatars.
_elgg_services()
Get the global service provider.
transfer($owner_guid, $filename=null)
Transfer a file to a new owner and sets a new filename, copies file contents to a new location...
open($mode)
Open the file with the given mode.
__sleep()
Get property names to serialize.