46 parent::initializeAttributes();
48 $this->attributes[
'subtype'] =
"file";
59 $this->filename =
$name;
78 return $this->
getFilestore()->getFilenameOnFilestore($this);
104 if ($this->mimetype) {
105 return $this->mimetype;
118 return $this->mimetype = $mimetype;
135 if (!
$file && isset($this) && $this instanceof
$class) {
139 if (!is_readable(
$file)) {
150 $original_filename = isset($this) && $this instanceof $class ? $this->originalfilename : basename(
$file);
153 'original_filename' => $original_filename,
167 if (isset($this->simpletype)) {
168 return $this->simpletype;
197 throw new IOException(
"You must specify a name before opening a file.");
205 (
$mode !=
"write") &&
208 $msg =
"Unrecognized file mode '" .
$mode .
"'";
215 return $this->handle;
257 $this->handle = null;
271 public function delete($follow_symlinks =
true) {
308 $modified = touch($filestorename);
310 clearstatcache(
true, $filestorename);
312 elgg_log(
"Unable to update modified time for $filestorename",
'ERROR');
389 $this->
open(
'write');
411 if (!$upload->isValid()) {
415 $old_filestorename =
'';
420 $originalfilename = $upload->getClientOriginalName();
421 $this->originalfilename = $originalfilename;
422 if (empty($this->title)) {
423 $this->title = htmlspecialchars($this->originalfilename, ENT_QUOTES,
'UTF-8');
426 $this->upload_time = time();
427 $prefix = $this->filestore_prefix ?:
'file';
428 $prefix = trim($prefix,
'/');
431 $this->filestore_prefix = $prefix;
438 $uploaded =
_elgg_services()->hooks->trigger(
'upload',
'file', $hook_params);
439 if ($uploaded !==
true && $uploaded !==
false) {
442 $uploaded = $upload->move(pathinfo($filestorename, PATHINFO_DIRNAME), pathinfo($filestorename, PATHINFO_BASENAME));
443 }
catch (FileException $ex) {
452 unlink($old_filestorename);
454 $mime_type = $this->
detectMimeType(null, $upload->getClientMimeType());
470 return array_diff(array_keys(get_object_vars($this)), [
500 $file_svc = new \Elgg\FileService\File();
501 $file_svc->setFile($this);
502 $file_svc->setExpires($expires);
503 $file_svc->setDisposition(
'attachment');
504 $file_svc->bindSession($use_cookie);
505 $url = $file_svc->getURL();
526 $file_svc = new \Elgg\FileService\File();
527 $file_svc->setFile($this);
528 if (!empty($expires)) {
529 $file_svc->setExpires($expires);
531 $file_svc->setDisposition(
'inline');
532 $file_svc->bindSession($use_cookie);
533 $url = $file_svc->getURL();
setDescription($description)
Set the optional file description.
getSize()
Return the size of the file in bytes.
if(!$user||!$user->canDelete()) $name
if(!array_key_exists($filename, $text_files)) $file
$params
Saves global plugin settings.
$mode
Configure site maintenance mode.
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.
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.
$user_guid
Validate a user.
initializeAttributes()
Set subtype to 'file'.
if(!$site) if(!($site instanceof ElggSite)) $site description
setMimeType($mimetype)
Set the mime type of the file.
getFilename()
Return the filename.
detectMimeType($file=null, $default=null)
Detects mime types based on filename or actual file.
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.
Detect the MIME type of a file.
getInlineURL($use_cookie=false, $expires= '')
Returns file's URL for inline display Suitable for displaying cacheable resources, such as user avatars.
setFilename($name)
Set the filename of this file.
_elgg_services()
Get the global service provider.
if(elgg_view_exists("plugins/{$plugin_id}/settings")) $description
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.
elgg_get_file_simple_type($mime_type)
Returns the category of a file from its MIME type.
__sleep()
Get property names to serialize.