ElggFile Class Reference

This class represents a physical file. More...

Inheritance diagram for ElggFile:
ElggObject ElggEntity ElggData Notable Locatable Importable Loggable Exportable

List of all members.

Public Member Functions

 __construct ($guid=null)
 Loads an ElggFile entity.
 setFilename ($name)
 Set the filename of this file.
 getFilename ()
 Return the filename.
 getFilenameOnFilestore ()
 Return the filename of this file as it is/will be stored on the filestore, which may be different to the filename.
 getFilestoreSize ($prefix= '', $container_guid=0)
 Return the size of the filestore associated with this file.
 getMimeType ()
 Get the mime type of the file.
 setMimeType ($mimetype)
 Set the mime type of the file.
 setDescription ($description)
 Set the optional file description.
 open ($mode)
 Open the file with the given mode.
 write ($data)
 Write data.
 read ($length, $offset=0)
 Read data.
 grabFile ()
 Gets the full contents of this file.
 close ()
 Close the file and commit changes.
 delete ()
 Delete this file.
 seek ($position)
 Seek a position in the file.
 tell ()
 Return the current position of the file.
 size ()
 Return the size of the file in bytes.
 eof ()
 Return a boolean value whether the file handle is at the end of the file.
 exists ()
 Returns if the file exists.
 setFilestore (ElggFilestore $filestore)
 Set a filestore.
 save ()
 Save the file.

Static Public Member Functions

static detectMimeType ($file=null, $default=null)
 Detects mime types based on filename or actual file.

Protected Member Functions

 initializeAttributes ()
 Set subtype to 'file'.
 getFilestore ()
 Return a filestore suitable for saving this file.

Detailed Description

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).

Definition at line 23 of file ElggFile.php.


Constructor & Destructor Documentation

ElggFile::__construct ( guid = null  ) 

Loads an ElggFile entity.

Parameters:
int $guid GUID of the ElggFile object

Reimplemented from ElggObject.

Definition at line 46 of file ElggFile.php.


Member Function Documentation

ElggFile::close (  ) 

Close the file and commit changes.

Returns:
bool

Definition at line 254 of file ElggFile.php.

ElggFile::delete (  ) 

Delete this file.

Returns:
bool

Reimplemented from ElggData.

Definition at line 271 of file ElggFile.php.

static ElggFile::detectMimeType ( file = null,
default = null 
) [static]

Detects mime types based on filename or actual file.

Parameters:
mixed $file The full path of the file to check. For uploaded files, use tmp_name.
mixed $default A default. Useful to pass what the browser thinks it is.
Since:
1.7.12
Returns:
mixed Detected type on success, false on failure.

Definition at line 132 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 316 of file ElggFile.php.

ElggFile::exists (  ) 

Returns if the file exists.

Returns:
bool

Definition at line 327 of file ElggFile.php.

ElggFile::getFilename (  ) 

Return the filename.

Returns:
string

Definition at line 69 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 79 of file ElggFile.php.

ElggFile::getFilestore (  )  [protected]

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

Definition at line 351 of file ElggFile.php.

ElggFile::getFilestoreSize ( prefix = '',
container_guid = 0 
)

Return the size of the filestore associated with this file.

Parameters:
string $prefix Storage prefix
int $container_guid The container GUID of the checked filestore
Returns:
int

Definition at line 91 of file ElggFile.php.

ElggFile::getMimeType (  ) 

Get the mime type of the file.

Returns:
string

Definition at line 104 of file ElggFile.php.

ElggFile::grabFile (  ) 

Gets the full contents of this file.

Returns:
mixed The file contents.

Definition at line 244 of file ElggFile.php.

ElggFile::initializeAttributes (  )  [protected]

Set subtype to 'file'.

Returns:
void

Reimplemented from ElggObject.

Definition at line 35 of file ElggFile.php.

ElggFile::open ( mode  ) 

Open the file with the given mode.

Parameters:
string $mode Either read/write/append
Returns:
resource File handler

Definition at line 182 of file ElggFile.php.

ElggFile::read ( length,
offset = 0 
)

Read data.

Parameters:
int $length Amount to read.
int $offset The offset to start from.
Returns:
mixed Data or false

Definition at line 233 of file ElggFile.php.

ElggFile::save (  ) 

Save the file.

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

See also:
ElggObject::save()
Returns:
bool

Reimplemented from ElggObject.

Definition at line 411 of file ElggFile.php.

ElggFile::seek ( position  ) 

Seek a position in the file.

Parameters:
int $position Position in bytes
Returns:
bool

Definition at line 285 of file ElggFile.php.

ElggFile::setDescription ( description  ) 

Set the optional file description.

Parameters:
string $description The description.
Returns:
bool

Definition at line 171 of file ElggFile.php.

ElggFile::setFilename ( name  ) 

Set the filename of this file.

Parameters:
string $name The filename.
Returns:
void

Definition at line 60 of file ElggFile.php.

ElggFile::setFilestore ( ElggFilestore filestore  ) 

Set a filestore.

Parameters:
ElggFilestore $filestore The file store.
Returns:
void

Definition at line 340 of file ElggFile.php.

ElggFile::setMimeType ( mimetype  ) 

Set the mime type of the file.

Parameters:
string $mimetype The mimetype
Returns:
bool

Definition at line 119 of file ElggFile.php.

ElggFile::size (  ) 

Return the size of the file in bytes.

Returns:
int

Definition at line 307 of file ElggFile.php.

ElggFile::tell (  ) 

Return the current position of the file.

Returns:
int The file position

Definition at line 296 of file ElggFile.php.

ElggFile::write ( data  ) 

Write data.

Parameters:
string $data The data
Returns:
bool

Definition at line 219 of file ElggFile.php.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations
Generated on Wed May 16 00:00:25 2012 for Elgg by  doxygen 1.6.3