4 use Symfony\Component\HttpFoundation\File\Exception\FileException;
5 use Symfony\Component\HttpFoundation\File\UploadedFile;
50 parent::initializeAttributes();
52 $this->attributes[
'subtype'] =
"file";
59 if (0 === strpos(
$name,
'filestore::')) {
60 elgg_deprecated_notice(
"Do not access the ElggFile filestore metadata directly. Use setFilestore().",
'2.0');
62 return parent::getMetadata(
$name);
69 if (0 === strpos(
$name,
'filestore::')) {
70 elgg_deprecated_notice(
"Do not access the ElggFile filestore metadata directly. Use setFilestore().",
'2.0');
83 $this->filename =
$name;
102 return $this->
getFilestore()->getFilenameOnFilestore($this);
128 if ($this->mimetype) {
129 return $this->mimetype;
141 return $this->mimetype = $mimetype;
158 if (!
$file && isset($this) && $this instanceof
$class) {
162 if (!is_readable(
$file)) {
173 $original_filename = isset($this) && $this instanceof
$class ? $this->originalfilename : basename(
$file);
176 'original_filename' => $original_filename,
190 if (isset($this->simpletype)) {
191 return $this->simpletype;
220 throw new IOException(
"You must specify a name before opening a file.");
228 (
$mode !=
"write") &&
231 $msg =
"Unrecognized file mode '" .
$mode .
"'";
243 return $this->handle;
280 return $fs->grabFile($this);
291 if ($fs->close($this->handle)) {
306 public function delete($follow_symlinks =
true) {
309 $result = $fs->delete($this, $follow_symlinks);
339 return $fs->tell($this->
handle);
348 $modified = touch($filestorename);
350 clearstatcache(
true, $filestorename);
352 elgg_log(
"Unable to update modified time for $filestorename",
'ERROR');
394 return $fs->eof($this->
handle);
405 return $fs->exists($this);
418 $this->filestore = $filestore;
431 if ($this->filestore) {
433 return $this->filestore;
437 $this->filestore = $GLOBALS[
'DEFAULT_FILE_STORE'];
440 return $this->filestore;
445 $class = parent::getMetadata(
'filestore::filestore');
447 return $this->filestore;
451 if (
$class === ElggDiskFilestore::class && parent::getMetadata(
'filestore::dir_root') ===
_elgg_services()->config->getDataPath()) {
452 return $this->filestore;
455 if (!class_exists(
$class)) {
456 $this->filestore =
null;
463 'guid' => $this->guid,
464 'where' => array(
"n.string LIKE 'filestore::%'"),
467 foreach ($mds as $md) {
468 list(,
$name) = explode(
"::", $md->name);
469 if (
$name !==
'filestore') {
470 $parameters[
$name] = $md->value;
474 $this->filestore =
new $class();
475 $this->filestore->setParameters($parameters);
476 return $this->filestore;
498 $params = $filestore->getParameters();
499 foreach (
$params as $k => $v) {
500 parent::setMetadata(
"filestore::$k", $v);
504 parent::setMetadata(
"filestore::filestore", get_class($filestore));
536 $this->
open(
'write');
558 if (!$upload->isValid()) {
562 $old_filestorename =
'';
567 $originalfilename = $upload->getClientOriginalName();
568 $this->originalfilename = $originalfilename;
569 if (empty($this->
title)) {
570 $this->
title = htmlspecialchars($this->originalfilename, ENT_QUOTES,
'UTF-8');
573 $this->upload_time =
time();
574 $prefix = $this->filestore_prefix ? :
'file';
575 $prefix = trim($prefix,
'/');
578 $this->filestore_prefix = $prefix;
585 $uploaded =
_elgg_services()->hooks->trigger(
'upload',
'file', $hook_params);
586 if ($uploaded !==
true && $uploaded !==
false) {
589 $uploaded = $upload->move(pathinfo($filestorename, PATHINFO_DIRNAME), pathinfo($filestorename, PATHINFO_BASENAME));
590 }
catch (FileException $ex) {
599 unlink($old_filestorename);
601 $mime_type = $this->
detectMimeType(
null, $upload->getClientMimeType());
617 return array_diff(array_keys(get_object_vars($this)), array(
$mode
Configure site maintenance mode.
if(! $site) if(!($site instanceof ElggSite)) $site description
if($guid==elgg_get_logged_in_user_guid()) $name
elgg module widget elgg state draggable elgg widget handle
getGUID()
Returns the guid.
setDescription($description)
Set the optional file description.
initializeAttributes()
Set subtype to 'file'.
setFilename($name)
Set the filename of this file.
getFilestore()
Return a filestore suitable for saving this file.
getSize()
Return the size of the file in bytes.
acceptUploadedFile(UploadedFile $upload)
Writes contents of the uploaded file to an instance of ElggFile.
seek($position)
Seek a position in the file.
read($length, $offset=0)
Read data.
setMetadata($name, $value, $value_type='', $multiple=false, $owner_guid=0, $access_id=null)
{Set metadata on this entity.Plugin developers usually want to use the magic set method ($entity->nam...
grabFile()
Gets the full contents of this file.
setMimeType($mimetype)
Set the mime type of the file.
getFilenameOnFilestore()
Return the filename of this file as it is/will be stored on the filestore, which may be different to ...
getModifiedTime()
Returns file modification time.
open($mode)
Open the file with the given mode.
__sleep()
Get property names to serialize.
getMetadata($name)
{Return the value of a piece of metadata.Namemixed The value, or null if not found....
getSimpleType()
Get the simple type of the file.
exists()
Returns if the file exists.
getMimeType()
Get the mime type of the file.
transfer($owner_guid, $filename=null)
Transfer a file to a new owner and sets a new filename, copies file contents to a new location.
getFilestoreSize($prefix='', $container_guid=0)
Return the size of the filestore associated with this file.
getFilename()
Return the filename.
setModifiedTime()
Updates modification time of the file and clears stats cache for the file.
setFilestore(ElggFilestore $filestore)
Set a filestore.
detectMimeType($file=null, $default=null)
Detects mime types based on filename or actual file.
eof()
Return a boolean value whether the file handle is at the end of the file.
close()
Close the file and commit changes.
tell()
Return the current position of the file.
size()
Return the size of the file in bytes.
Detect the MIME type of a file.
elgg river item elgg form comment save
elgg_log($message, $level='NOTICE')
Display or log a message.
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
elgg_get_file_simple_type($mime_type)
Returns the category of a file from its MIME type.
elgg_strtolower()
Wrapper function for mb_strtolower().
if($categories) $description
if(!array_key_exists($filename, $text_files)) $file