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);
138 if ($this->mimetype) {
139 return $this->mimetype;
159 return $this->mimetype = $mimetype;
169 if (isset($this->simpletype)) {
170 return $this->simpletype;
188 throw new IOException(
'You must specify a name before opening a file.');
196 (
$mode !=
'write') &&
205 return $this->handle;
247 $this->handle = null;
262 public function delete($follow_symlinks =
true) {
300 $modified = touch($filestorename);
302 clearstatcache(
true, $filestorename);
304 elgg_log(
"Unable to update modified time for {$filestorename}",
'ERROR');
384 $this->
open(
'write');
407 if (!$upload->isValid()) {
411 $old_filestorename =
'';
416 $originalfilename = $upload->getClientOriginalName();
417 $this->originalfilename = $originalfilename;
418 if (empty($this->title)) {
419 $this->title = htmlspecialchars($this->originalfilename, ENT_QUOTES,
'UTF-8');
422 $this->upload_time = time();
423 $prefix = $this->filestore_prefix ?:
'file';
424 $prefix =
trim($prefix,
'/');
427 $this->filestore_prefix = $prefix;
434 $uploaded =
_elgg_services()->hooks->trigger(
'upload',
'file', $hook_params);
435 if ($uploaded !==
true && $uploaded !==
false) {
438 $uploaded = $upload->move(pathinfo($filestorename, PATHINFO_DIRNAME), pathinfo($filestorename, PATHINFO_BASENAME));
439 }
catch (FileException $ex) {
448 unlink($old_filestorename);
455 $this->simpletype =
_elgg_services()->mimetype->getSimpleType($mime_type);
473 return array_diff(array_keys(get_object_vars($this)), [
502 $file_svc = new \Elgg\FileService\File();
503 $file_svc->setFile($this);
504 if (!empty($expires)) {
505 $file_svc->setExpires($expires);
507 $file_svc->setDisposition(
'attachment');
508 $file_svc->bindSession($use_cookie);
528 $file_svc = new \Elgg\FileService\File();
529 $file_svc->setFile($this);
530 if (!empty($expires)) {
531 $file_svc->setExpires($expires);
533 $file_svc->setDisposition(
'inline');
534 $file_svc->bindSession($use_cookie);
getSize()
Return the size of the file in bytes.
if(!$user||!$user->canDelete()) $name
$params
Saves global plugin settings.
$mode
Configure site maintenance mode.
An IO Exception, throw when an IO Exception occurs.
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.