Overview

Packages

  • ClipIt
    • clipit
      • api
    • urjc
      • backend
  • Elgg
    • Core
      • Access
      • Authentication
      • Cache
      • Caches
      • Core
      • DataMode
        • Site
      • DataModel
        • Annotations
        • Entities
        • Extender
        • File
        • Importable
        • Loggable
        • Notable
        • Object
        • User
      • DataStorage
      • Exception
      • Exceptions
        • Stub
      • FileStore
        • Disk
      • Groups
      • Helpers
      • HMAC
      • Memcache
      • Metadata
      • Navigation
      • ODD
      • Output
      • Plugins
        • Settings
      • Sessions
      • SocialModel
        • Friendable
        • Locatable
      • WebServicesAPI
      • Widgets
      • XML
      • XMLRPC
    • Exceptions
      • Stub
  • None
  • PHP

Classes

  • ElggFile
  • Overview
  • Package
  • Class
  • Tree

Class ElggFile

This class represents a physical file.

Create a new ElggFile object and specify a filename, and optionally a FileStore (if one isn't specified then the default is assumed.)

Open the file using the appropriate mode, and you will be able to read and write to the file.

Optionally, you can also call the file's save() method, this will turn the file into an entity in the system and permit you to do things like attach tags to the file etc. This is not done automatically since there are many occasions where you may want access to file data on datastores using the ElggFile interface but do not want to create an Entity reference to it in the system (temporary files for example).

ElggData implements Loggable, Iterator, ArrayAccess, Exportable
Extended by ElggEntity implements Notable, Locatable, Importable
Extended by ElggObject
Extended by ElggFile
Package: Elgg\Core\DataModel\File
Class: ElggFile
Located at ElggFile.php
Methods summary
protected
# initializeAttributes( )

Set subtype to 'file'.

Set subtype to 'file'.

Overrides

ElggObject::initializeAttributes()
public
# __construct( integer $guid = null )

Loads an ElggFile entity.

Loads an ElggFile entity.

Parameters

$guid
integer
$guid GUID of the ElggFile object

Throws

IOException
If passed an incorrect guid
InvalidParameterException
If passed an Elgg* Entity that isn't an ElggObject

Overrides

ElggObject::__construct()
public
# setFilename( string $name )

Set the filename of this file.

Set the filename of this file.

Parameters

$name
string
$name The filename.
public string
# getFilename( )

Return the filename.

Return the filename.

Returns

string
public string
# getFilenameOnFilestore( )

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

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

Returns

string
public integer
# getFilestoreSize( string $prefix = '', integer $container_guid = 0 )

Return the size of the filestore associated with this file

Return the size of the filestore associated with this file

Parameters

$prefix
string
$prefix Storage prefix
$container_guid
integer
$container_guid The container GUID of the checked filestore

Returns

integer
public string
# getMimeType( )

Get the mime type of the file.

Get the mime type of the file.

Returns

string
public boolean
# setMimeType( string $mimetype )

Set the mime type of the file.

Set the mime type of the file.

Parameters

$mimetype
string
$mimetype The mimetype

Returns

boolean
public mixed
# detectMimeType( mixed $file = null, mixed $default = null )

Detects mime types based on filename or actual file.

Detects mime types based on filename or actual file.

Parameters

$file
mixed
$file The full path of the file to check. For uploaded files, use tmp_name.
$default
mixed
$default A default. Useful to pass what the browser thinks it is.

Returns

mixed
Detected type on success, false on failure.

Since

1.7.12

Note

If $file is provided, this may be called statically
public boolean
# setDescription( string $description )

Set the optional file description.

Set the optional file description.

Parameters

$description
string
$description The description.

Returns

boolean
public resource
# open( string $mode )

Open the file with the given mode

Open the file with the given mode

Parameters

$mode
string
$mode Either read/write/append

Returns

resource
File handler

Throws

IOException|InvalidParameterException
public boolean
# write( string $data )

Write data.

Write data.

Parameters

$data
string
$data The data

Returns

boolean
public mixed
# read( integer $length, integer $offset = 0 )

Read data.

Read data.

Parameters

$length
integer
$length Amount to read.
$offset
integer
$offset The offset to start from.

Returns

mixed
Data or false
public mixed
# grabFile( )

Gets the full contents of this file.

Gets the full contents of this file.

Returns

mixed
The file contents.
public boolean
# close( )

Close the file and commit changes

Close the file and commit changes

Returns

boolean
public boolean
# delete( )

Delete this file.

Delete this file.

Returns

boolean

Overrides

ElggEntity::delete()
public boolean
# seek( integer $position )

Seek a position in the file.

Seek a position in the file.

Parameters

$position
integer
$position Position in bytes

Returns

boolean
public integer
# tell( )

Return the current position of the file.

Return the current position of the file.

Returns

integer
The file position
public integer
# size( )

Return the size of the file in bytes.

Return the size of the file in bytes.

Returns

integer
public boolean
# eof( )

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

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

Returns

boolean
public boolean
# exists( )

Returns if the file exists

Returns if the file exists

Returns

boolean
public
# setFilestore( ElggFilestore $filestore )

Set a filestore.

Set a filestore.

Parameters

$filestore
ElggFilestore
$filestore The file store.
protected ElggFilestore
# getFilestore( )

Return a filestore suitable for saving this file. This filestore is either a pre-registered filestore, a filestore as recorded in metadata or the system default.

Return a filestore suitable for saving this file. This filestore is either a pre-registered filestore, a filestore as recorded in metadata or the system default.

Returns

ElggFilestore

Throws

ClassNotFoundException
public boolean
# save( )

Save the file

Save the file

Write the file's data to the filestore and save the corresponding entity.

Returns

boolean

Throws

IOException

See

ElggObject::save()

Overrides

ElggObject::save()
Methods inherited from ElggObject
addToSite(), canComment(), getExportableValues(), getSites(), load()
Methods inherited from ElggEntity
__clone(), __unset(), addRelationship(), annotate(), canAnnotate(), canEdit(), canEditMetadata(), canWriteToContainer(), countAnnotations(), countComments(), countEntitiesFromRelationship(), deleteAnnotations(), deleteMetadata(), deleteOwnedAnnotations(), deleteOwnedMetadata(), deleteRelationships(), disable(), disableAnnotations(), disableMetadata(), enable(), enableAnnotations(), enableMetadata(), export(), get(), getAccessID(), getAnnotations(), getAnnotationsAvg(), getAnnotationsMax(), getAnnotationsMin(), getAnnotationsSum(), getCalendarEndTime(), getCalendarStartTime(), getContainerEntity(), getContainerGUID(), getEntitiesFromRelationship(), getGUID(), getIconURL(), getLatitude(), getLocation(), getLongitude(), getMetaData(), getObjectFromID(), getOwnerEntity(), getOwnerGUID(), getPrivateSetting(), getSubtype(), getSystemLogID(), getTags(), getTimeUpdated(), getType(), getURL(), getVolatileData(), import(), isEnabled(), isFullyLoaded(), removePrivateSetting(), removeRelationship(), set(), setCalendarTimeAndDuration(), setContainerGUID(), setLatLong(), setLocation(), setMetaData(), setPrivateSetting(), setURL(), setVolatileData()
Methods inherited from ElggData
__get(), __isset(), __set(), current(), getClassName(), getTimeCreated(), key(), next(), offsetExists(), offsetGet(), offsetSet(), offsetUnset(), rewind(), valid()
Properties inherited from ElggEntity
$icon_override, $temp_annotations, $temp_metadata, $temp_private_settings, $url_override, $volatile
Properties inherited from ElggData
$attributes, $valid
Magic properties inherited from ElggObject
$description, $tags, $title
Magic properties inherited from ElggEntity
$access_id, $container_guid, $enabled, $guid, $owner_guid, $site_guid, $subtype, $time_created, $time_updated, $type
API documentation generated by ApiGen 2.8.0