Elgg  Version master
Public Member Functions | Protected Member Functions | List of all members
ElggFile Class Reference
Inheritance diagram for ElggFile:
ElggObject ElggEntity ElggData Elgg\Collections\CollectionItemInterface ElggIcon ElggTempFile

Public Member Functions

 __set ($name, $value)
 
 __get ($name)
 
 setFilename (string $filename)
 Set the filename of this file. More...
 
 getFilename ()
 Return the filename. More...
 
 getFilenameOnFilestore ()
 Return the filename of this file as it is/will be stored on the filestore, which may be different to the filename. More...
 
 getMimeType ()
 Get the mime type of the file. More...
 
 setMimeType (string $mimetype)
 Set the mime type of the file. More...
 
 getSimpleType ()
 Get the simple type of the file. More...
 
 open (string $mode)
 Open the file with the given mode. More...
 
 write (string $data)
 Write data. More...
 
 read (int $length, int $offset=0)
 Read data. More...
 
 grabFile ()
 Gets the full contents of this file. More...
 
 close ()
 Close the file and commit changes. More...
 
 delete (bool $recursive=true, bool $persistent=null)
 {} More...
 
 seek (int $position)
 Seek a position in the file. More...
 
 tell ()
 Return the current position of the file. More...
 
 setModifiedTime ()
 Updates modification time of the file and clears stats cache for the file. More...
 
 getModifiedTime ()
 Returns file modification time. More...
 
 getSize ()
 Return the size of the file in bytes. More...
 
 eof ()
 Return a boolean value whether the file handle is at the end of the file. More...
 
 exists ()
 Returns if the file exists. More...
 
 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. More...
 
 acceptUploadedFile (UploadedFile $upload)
 Writes contents of the uploaded file to an instance of ElggFile. More...
 
 __sleep ()
 Get property names to serialize. More...
 
 canDownload (int $user_guid=0, bool $default=true)
 Checks the download permissions for the file. More...
 
 getDownloadURL (bool $use_cookie=true, string $expires= '+2 hours')
 Returns file's download URL. More...
 
 getInlineURL (bool $use_cookie=false, string $expires= '')
 Returns file's URL for inline display Suitable for displaying cacheable resources, such as user avatars. More...
 
- Public Member Functions inherited from ElggObject
 getType ()
 {} More...
 
 getDisplayName ()
 {} More...
 
 setDisplayName (string $display_name)
 {} More...
 
- Public Member Functions inherited from ElggEntity
 __construct (stdClass $row=null)
 Create a new entity. More...
 
 __clone ()
 Clone an entity. More...
 
 __set ($name, $value)
 Set an attribute or metadata value for this entity. More...
 
 getOriginalAttributes ()
 Get the original values of attribute(s) that have been modified since the entity was persisted. More...
 
 __get ($name)
 Get an attribute or metadata value. More...
 
 getDisplayName ()
 Get the entity's display name. More...
 
 setDisplayName (string $display_name)
 Sets the title or name of this entity. More...
 
 getMetadata (string $name)
 Return the value of a piece of metadata. More...
 
 getAllMetadata ()
 Get all entity metadata. More...
 
 setMetadata (string $name, $value, string $value_type= '', bool $multiple=false)
 Set metadata on this entity. More...
 
 deleteMetadata (string $name=null)
 Deletes all metadata on this object (metadata.entity_guid = $this->guid). More...
 
 getVolatileData (string $name)
 Get a piece of volatile (non-persisted) data on this entity. More...
 
 setVolatileData (string $name, $value)
 Set a piece of volatile (non-persisted) data on this entity. More...
 
 addRelationship (int $guid_two, string $relationship)
 Add a relationship between this an another entity. More...
 
 hasRelationship (int $guid_two, string $relationship)
 Check if this entity has a relationship with another entity. More...
 
 getRelationship (int $guid_two, string $relationship)
 Return the relationship if this entity has a relationship with another entity. More...
 
 getEntitiesFromRelationship (array $options=[])
 Gets an array of entities with a relationship to this entity. More...
 
 countEntitiesFromRelationship (string $relationship, bool $inverse_relationship=false)
 Gets the number of entities from a specific relationship type. More...
 
 removeRelationship (int $guid_two, string $relationship)
 Remove a relationship. More...
 
 removeAllRelationships (string $relationship= '', bool $inverse_relationship=false)
 Remove all relationships to or from this entity. More...
 
 removeAllRelatedRiverItems ()
 Removes all river items related to this entity. More...
 
 deleteAnnotations (string $name=null)
 Deletes all annotations on this object (annotations.entity_guid = $this->guid). More...
 
 deleteOwnedAnnotations (string $name=null)
 Deletes all annotations owned by this object (annotations.owner_guid = $this->guid). More...
 
 annotate ($name, $value, $access_id=ACCESS_PRIVATE, $owner_guid=0, $value_type= '')
 Adds an annotation to an entity. More...
 
 getAnnotations (array $options=[])
 Gets an array of annotations. More...
 
 countAnnotations (string $name= '')
 Count annotations. More...
 
 getAnnotationsAvg (string $name)
 Get the average of an integer type annotation. More...
 
 getAnnotationsSum (string $name)
 Get the sum of integer type annotations of a given name. More...
 
 getAnnotationsMin (string $name)
 Get the minimum of integer type annotations of given name. More...
 
 getAnnotationsMax (string $name)
 Get the maximum of integer type annotations of a given name. More...
 
 countComments ()
 Count the number of comments attached to this entity. More...
 
 getOwnedAccessCollections (array $options=[])
 Returns the ACLs owned by the entity. More...
 
 getOwnedAccessCollection (string $subtype)
 Returns the first ACL owned by the entity with a given subtype. More...
 
 hasAccess (int $user_guid=0)
 Check if the given user has access to this entity. More...
 
 canEdit (int $user_guid=0)
 Can a user edit this entity? More...
 
 canDelete (int $user_guid=0)
 Can a user delete this entity? More...
 
 canWriteToContainer (int $user_guid=0, string $type= '', string $subtype= '')
 Can a user add an entity to this container. More...
 
 canComment (int $user_guid=0)
 Can a user comment on an entity? More...
 
 canAnnotate (int $user_guid=0, string $annotation_name= '')
 Can a user annotate an entity? More...
 
 getGUID ()
 Returns the guid. More...
 
 getType ()
 Returns the entity type. More...
 
 setSubtype (string $subtype)
 Set the subtype of the entity. More...
 
 getSubtype ()
 Get the entity subtype. More...
 
 getOwnerGUID ()
 Get the guid of the entity's owner. More...
 
 getOwnerEntity ()
 Gets the that owns this entity. More...
 
 setContainerGUID (int $container_guid)
 Set the container for this object. More...
 
 getContainerGUID ()
 Gets the container GUID for this entity. More...
 
 getContainerEntity ()
 Get the container entity for this object. More...
 
 getTimeUpdated ()
 Returns the UNIX epoch time that this entity was last updated. More...
 
 getURL ()
 Gets the URL for this entity. More...
 
 save ()
 
 disable (string $reason= '', bool $recursive=true)
 Disable this entity. More...
 
 enable (bool $recursive=true)
 Enable the entity. More...
 
 isEnabled ()
 Is this entity enabled? More...
 
 delete (bool $recursive=true, bool $persistent=null)
 Deletes the entity. More...
 
 restore (bool $recursive=true)
 Restore the entity. More...
 
 isDeleted ()
 Is the entity marked as deleted. More...
 
 toObject (array $params=[])
 Export an entity. More...
 
 setLatLong (float $lat, float $long)
 Set latitude and longitude metadata tags for a given entity. More...
 
 getLatitude ()
 Return the entity's latitude. More...
 
 getLongitude ()
 Return the entity's longitude. More...
 
 getSystemLogID ()
 {} More...
 
 getObjectFromID (int $id)
 For a given ID, return the object associated with it. More...
 
 deleteAccessCollectionMemberships ()
 Remove the membership of all access collections for this entity (if the entity is a user) More...
 
 deleteOwnedAccessCollections ()
 Remove all access collections owned by this entity. More...
 
 updateLastAction (int $posted=null)
 Update the last_action column in the entities table. More...
 
 updateTimeDeleted (int $deleted=null)
 Update the time_deleted column in the entities table. More...
 
 disableCaching ()
 Disable runtime caching for entity. More...
 
 enableCaching ()
 Enable runtime caching for entity. More...
 
 isCacheable ()
 Is entity cacheable in the runtime cache. More...
 
 cache ()
 Cache the entity in a session cache. More...
 
 invalidateCache ()
 Invalidate cache for entity. More...
 
 hasCapability (string $capability)
 Checks a specific capability is enabled for the entity type/subtype. More...
 
- Public Member Functions inherited from ElggData
 __isset ($name)
 Test if property is set either as an attribute or metadata. More...
 
 __unset ($name)
 Unset a property from metadata or attribute. More...
 
 getURL ()
 Get a URL for this object. More...
 
 save ()
 Save this data to the appropriate database table. More...
 
 delete ()
 Delete this data. More...
 
 getTimeCreated ()
 Returns the UNIX epoch time that this entity was created. More...
 
 toObject (array $params=[])
 Get a plain old object copy for public consumption. More...
 
 getSystemLogID ()
 Return an identification for the object for storage in the system log. More...
 
 getType ()
 Return the type of the object - eg. More...
 
 getSubtype ()
 Return a subtype. More...
 
 getObjectFromID (int $id)
 For a given ID, return the object associated with it. More...
 
 rewind ()
 Iterator interface. More...
 
 current ()
 Iterator interface. More...
 
 key ()
 Iterator interface. More...
 
 next ()
 Iterator interface. More...
 
 valid ()
 Iterator interface. More...
 
 offsetSet ($offset, $value)
 Array access interface. More...
 
 offsetGet ($offset)
 Array access interface. More...
 
 offsetUnset ($offset)
 Array access interface. More...
 
 offsetExists ($offset)
 Array access interface. More...
 
 getID ()
 {Get unique item identifier within a collection.
Returns
string|int
} More...
 
 getPriority ()
 {Get priority (weight) of the item within a collection.
Returns
int
} More...
 
 __serialize ()
 Called during serialization. More...
 
 __unserialize (array $data)
 Called during unserialization. More...
 

Protected Member Functions

 initializeAttributes ()
 Set subtype to 'file'. More...
 
 persistentDelete (bool $recursive=true)
 {} More...
 
 getFilestore ()
 Return the system filestore based on dataroot. More...
 
- Protected Member Functions inherited from ElggObject
 prepareObject (\Elgg\Export\Entity $object)
 {} More...
 
- Protected Member Functions inherited from ElggEntity
 initializeAttributes ()
 Initialize the attributes array. More...
 
 setTempMetadata (string $name, $value, bool $multiple=false)
 Set temp metadata on this entity. More...
 
 create ()
 Create a new entry in the entities table. More...
 
 update ()
 Update the entity in the database. More...
 
 load (stdClass $row)
 Loads attributes from the entities table into the object. More...
 
 persistentDelete (bool $recursive=true)
 Permanently delete the entity from the database. More...
 
 trash (bool $recursive=true)
 Move the entity to the trash. More...
 
 prepareObject (\Elgg\Export\Entity $object)
 Prepare an object copy for toObject() More...
 
- Protected Member Functions inherited from ElggData
 initializeAttributes ()
 Initialize the attributes array. More...
 
 getDatabase ()
 Provides a pointer to the database object. More...
 

Additional Inherited Members

- Public Attributes inherited from ElggEntity
const PRIMARY_ATTR_NAMES
 
- Protected Attributes inherited from ElggEntity
const INTEGER_ATTR_NAMES
 
 $temp_metadata = []
 
 $temp_annotations = []
 
 $volatile = []
 
 $orig_attributes = []
 
 $_is_cacheable = true
 
 $_cached_metadata
 
- Protected Attributes inherited from ElggData
 $attributes = []
 
 $valid = false
 

Detailed Description

Definition at line 32 of file ElggFile.php.

Member Function Documentation

ElggFile::__get (   $name)

Definition at line 68 of file ElggFile.php.

ElggFile::__set (   $name,
  $value 
)

Definition at line 54 of file ElggFile.php.

ElggFile::__sleep ( )

Get property names to serialize.

Returns
string[]

Definition at line 462 of file ElggFile.php.

ElggFile::acceptUploadedFile ( UploadedFile  $upload)

Writes contents of the uploaded file to an instance of ElggFile.

Note
Note that this function moves the file and populates properties, but does not call ElggFile::save().
This method will automatically assign a filename on filestore based on the upload time and filename. By default, the file will be written to /file directory on owner's filestore. You can change this directory, by setting 'filestore_prefix' property of the ElggFile instance before calling this method.
Parameters
UploadedFile$uploadUploaded file object
Returns
bool

Definition at line 395 of file ElggFile.php.

ElggFile::canDownload ( int  $user_guid = 0,
bool  $default = true 
)

Checks the download permissions for the file.

Parameters
int$user_guidGUID of the user (defaults to logged in user)
bool$defaultDefault permission
Returns
bool

Definition at line 477 of file ElggFile.php.

ElggFile::close ( )

Close the file and commit changes.

Returns
bool

Definition at line 223 of file ElggFile.php.

ElggFile::delete ( bool  $recursive = true,
bool  $persistent = null 
)

{}

Definition at line 236 of file ElggFile.php.

ElggFile::eof ( )

Return a boolean value whether the file handle is at the end of the file.

Returns
bool

Definition at line 322 of file ElggFile.php.

ElggFile::exists ( )

Returns if the file exists.

Returns
bool

Definition at line 331 of file ElggFile.php.

ElggFile::getDownloadURL ( bool  $use_cookie = true,
string  $expires = '+2 hours' 
)

Returns file's download URL.

Note
This does not work for files with custom filestores.
Parameters
bool$use_cookieLimit URL validity to current session only
string$expiresURL expiration, as a string suitable for strtotime()
Returns
string|null

Definition at line 491 of file ElggFile.php.

ElggFile::getFilename ( )

Return the filename.

This filename will be sanitized to prevent path traversal

Returns
string

Definition at line 96 of file ElggFile.php.

ElggFile::getFilenameOnFilestore ( )

Return the filename of this file as it is/will be stored on the filestore, which may be different to the filename.

Returns
string

Definition at line 111 of file ElggFile.php.

ElggFile::getFilestore ( )
protected

Return the system filestore based on dataroot.

Returns

Definition at line 340 of file ElggFile.php.

ElggFile::getInlineURL ( bool  $use_cookie = false,
string  $expires = '' 
)

Returns file's URL for inline display Suitable for displaying cacheable resources, such as user avatars.

Note
This does not work for files with custom filestores.
Parameters
bool$use_cookieLimit URL validity to current session only
string$expiresURL expiration, as a string suitable for strtotime()
Returns
string|null

Definition at line 520 of file ElggFile.php.

ElggFile::getMimeType ( )

Get the mime type of the file.

Returns mimetype metadata value if set, otherwise attempts to detect it.

Returns
string|false

Definition at line 121 of file ElggFile.php.

ElggFile::getModifiedTime ( )

Returns file modification time.

Returns
int

Definition at line 303 of file ElggFile.php.

ElggFile::getSimpleType ( )

Get the simple type of the file.

Returns simpletype metadata value if set, otherwise parses it from mimetype

Returns
string 'document', 'audio', 'video', or 'general' if the MIME type was unrecognized

Definition at line 153 of file ElggFile.php.

ElggFile::getSize ( )

Return the size of the file in bytes.

Returns
int
Since
1.9

Definition at line 313 of file ElggFile.php.

ElggFile::grabFile ( )

Gets the full contents of this file.

Returns
false|string The file contents.

Definition at line 214 of file ElggFile.php.

ElggFile::initializeAttributes ( )
protected

Set subtype to 'file'.

Returns
void

Definition at line 45 of file ElggFile.php.

ElggFile::open ( string  $mode)

Open the file with the given mode.

Parameters
string$modeEither read/write/append
Returns
false|resource File handler
Exceptions
IOException

Definition at line 171 of file ElggFile.php.

ElggFile::persistentDelete ( bool  $recursive = true)
protected

{}

Definition at line 247 of file ElggFile.php.

ElggFile::read ( int  $length,
int  $offset = 0 
)

Read data.

Parameters
int$lengthAmount to read.
int$offsetThe offset to start from.
Returns
mixed Data or false

Definition at line 205 of file ElggFile.php.

ElggFile::seek ( int  $position)

Seek a position in the file.

Parameters
int$positionPosition in bytes
Returns
void

Definition at line 267 of file ElggFile.php.

ElggFile::setFilename ( string  $filename)

Set the filename of this file.

This filename will be sanitized to prevent path traversal

Parameters
string$filenameThe filename
Returns
void

Definition at line 85 of file ElggFile.php.

ElggFile::setMimeType ( string  $mimetype)

Set the mime type of the file.

Parameters
string$mimetypeThe mimetype
Returns
void

Definition at line 143 of file ElggFile.php.

ElggFile::setModifiedTime ( )

Updates modification time of the file and clears stats cache for the file.

Returns
bool

Definition at line 285 of file ElggFile.php.

ElggFile::tell ( )

Return the current position of the file.

Returns
int The file position

Definition at line 276 of file ElggFile.php.

ElggFile::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.

This is an alternative to using rename() which fails to move files to a non-existent directory under new owner's filestore directory

Parameters
int$owner_guidNew owner's guid
string$filenameNew filename (uses old filename if not set)
Returns
bool

Definition at line 356 of file ElggFile.php.

ElggFile::write ( string  $data)

Write data.

Parameters
string$dataThe data
Returns
false|int

Definition at line 193 of file ElggFile.php.


The documentation for this class was generated from the following file: