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;
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(
setDescription($description)
Set the optional file description.
getSize()
Return the size of the file in bytes.
elgg module widget elgg state draggable elgg widget handle
if(!array_key_exists($filename, $text_files)) $file
$mode
Configure site maintenance mode.
setMetadata($name, $value, $value_type= '', $multiple=false, $owner_guid=0, $access_id=null)
{}
if($guid==elgg_get_logged_in_user_guid()) $name
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.
getSimpleType()
Get the simple type of the file.
getGUID()
Returns the guid.
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.
initializeAttributes()
Set subtype to 'file'.
if(!$site) if(!($site instanceof ElggSite)) $site description
setMimeType($mimetype)
Set the mime type of the file.
if($categories) $description
getFilename()
Return the filename.
detectMimeType($file=null, $default=null)
Detects mime types based on filename or actual file.
read($length, $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.
elgg river item elgg form comment save
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
open($mode)
Open the file with the given mode.
setFilestore(ElggFilestore $filestore)
Set a filestore.
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
elgg_log($message, $level= 'NOTICE')
Display or log a message.
getFilestore()
Return a filestore suitable for saving this file.
Detect the MIME type of a file.
setFilename($name)
Set the filename of this file.
size()
Return the size of the file in bytes.
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
transfer($owner_guid, $filename=null)
Transfer a file to a new owner and sets a new filename, copies file contents to a new location...
elgg_get_file_simple_type($mime_type)
Returns the category of a file from its MIME type.
__sleep()
Get property names to serialize.