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;
240 public function delete(
bool $follow_symlinks =
true):
bool {
278 $modified = touch($filestorename);
280 clearstatcache(
true, $filestorename);
282 elgg_log(
"Unable to update modified time for {$filestorename}",
'ERROR');
312 public function eof(): bool {
347 if ($owner_guid < 1) {
363 $this->
open(
'write');
386 if (!$upload->isValid()) {
390 $old_filestorename =
'';
395 $originalfilename = $upload->getClientOriginalName();
396 $this->originalfilename = $originalfilename;
397 if (empty($this->title)) {
398 $this->title = htmlspecialchars($this->originalfilename, ENT_QUOTES,
'UTF-8');
401 $this->upload_time = time();
402 $prefix = $this->filestore_prefix ?:
'file';
403 $prefix =
trim($prefix,
'/');
406 $this->filestore_prefix = $prefix;
414 if ($uploaded !==
true && $uploaded !==
false) {
417 $uploaded = $upload->move(pathinfo($filestorename, PATHINFO_DIRNAME), pathinfo($filestorename, PATHINFO_BASENAME));
418 }
catch (FileException $ex) {
427 unlink($old_filestorename);
434 $this->simpletype =
_elgg_services()->mimetype->getSimpleType($mime_type);
453 return array_diff(array_keys(get_object_vars($this)), [
481 public function getDownloadURL(
bool $use_cookie =
true,
string $expires =
'+2 hours'): ?string {
482 $file_svc = new \Elgg\FileService\File();
483 $file_svc->setFile($this);
484 if (!empty($expires)) {
485 $file_svc->setExpires($expires);
488 $file_svc->setDisposition(
'attachment');
489 $file_svc->bindSession($use_cookie);
493 'use_cookie' => $use_cookie,
494 'expires' => $expires,
496 return _elgg_services()->events->triggerResults(
'download:url',
'file',
$params, $file_svc->getURL());
510 public function getInlineURL(
bool $use_cookie =
false,
string $expires =
''): ?string {
511 $file_svc = new \Elgg\FileService\File();
512 $file_svc->setFile($this);
513 if (!empty($expires)) {
514 $file_svc->setExpires($expires);
517 $file_svc->setDisposition(
'inline');
518 $file_svc->bindSession($use_cookie);
522 'use_cookie' => $use_cookie,
523 'expires' => $expires,
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.
getGUID()
Returns the guid.
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.
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.