46 parent::initializeAttributes();
48 $this->attributes[
'subtype'] =
'file';
75 return parent::__get(
$name);
86 $filename = ltrim(Paths::sanitize($filename,
false),
'/');
88 parent::__set(
'filename', $filename);
102 return ltrim(Paths::sanitize(
$filename,
false),
'/');
112 return $this->
getFilestore()->getFilenameOnFilestore($this);
122 if ($this->mimetype) {
123 return $this->mimetype;
144 $this->mimetype = $mimetype;
154 if (isset($this->simpletype)) {
155 return $this->simpletype;
173 throw new IOException(
'You must specify a name before opening a file.');
176 if (!in_array($mode, [
'read',
'write',
'append'])) {
181 $this->handle = $this->
getFilestore()->open($this, $mode);
183 return $this->handle;
194 return $this->
getFilestore()->write($this->handle, $data);
225 $this->handle = null;
236 public function delete(
bool $recursive =
true,
bool $persistent = null):
bool {
241 return parent::delete($recursive, $persistent);
249 $result = parent::persistentDelete($recursive);
288 $modified = touch($filestorename);
290 clearstatcache(
true, $filestorename);
292 elgg_log(
"Unable to update modified time for {$filestorename}", \Psr\Log\LogLevel::ERROR);
322 public function eof(): bool {
357 if ($owner_guid < 1) {
373 $this->
open(
'write');
396 if (!$upload->isValid()) {
400 $old_filestorename =
'';
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) {
427 $uploaded = $upload->move(pathinfo($filestorename, PATHINFO_DIRNAME), pathinfo($filestorename, PATHINFO_BASENAME));
428 }
catch (FileException $ex) {
437 unlink($old_filestorename);
444 $this->simpletype =
_elgg_services()->mimetype->getSimpleType($mime_type);
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,
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.
close()
Close the file and commit changes.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
eof()
Return a boolean value whether the file handle is at the end of the file.
exists()
Returns if the file exists.
getSimpleType()
Get the simple type of the file.
seek(int $position)
Seek a position in the file.
getInlineURL(bool $use_cookie=false, string $expires= '')
Returns file's URL for inline display Suitable for displaying cacheable resources, such as user avatars.
persistentDelete(bool $recursive=true)
{}
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 ...
setFilename(string $filename)
Set the filename of this file.
grabFile()
Gets the full contents of this file.
getFilestore()
Return the system filestore based on dataroot.
if(!$entity instanceof\ElggUser) $data
canDownload(int $user_guid=0, bool $default=true)
Checks the download permissions for the file.
initializeAttributes()
Set subtype to 'file'.
getFilename()
Return the filename.
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
read(int $length, int $offset=0)
Read data.
tell()
Return the current position of the file.
acceptUploadedFile(UploadedFile $upload)
Writes contents of the uploaded file to an instance of ElggFile.
getMimeType()
Get the mime type of the file.
write(string $data)
Write data.
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...
getDownloadURL(bool $use_cookie=true, string $expires= '+2 hours')
Returns file's download URL.
setMimeType(string $mimetype)
Set the mime type of the file.
_elgg_services()
Get the global service provider.
open(string $mode)
Open the file with the given mode.
__sleep()
Get property names to serialize.