This is the documentation for concrete5 version 5.6 and earlier. View Current Documentation

File Object

The File class provides the best way to access the File object. Most methods can be performed on the File object itself, including FileVersion methods.

$f = File::getByID($fileID)

Returns a file by ID. By default, this will return all version-specific information from the approved version of the file.

$f->getPath()

Returns a full path to the current file version.

$f->getPassword()

Returns a clear text password if a file is password protected.

$fsID = $f->getFileStorageLocationID()

Returns an ID of a FileStorageLocation object for the current file.

$f->refreshCache()

Clears all cached information about a file, including the cache for all its versions.

$f->reindex()

Reindexes all custom attribute search information about a file.

$path = File::getRelativePathFromID($fileID)

A helper function. Get a relative path for a file ID.

$f->setStorageLocation($item)

Sets a files storage location. If $item == 0, the default storage location will be used. Otherwise, $item must equal a valid FileStorageLocation object.

$f->setPassword($password)

Sets the password on a file object.

$f->resetPermissions()

Resets permissions on a file object.

$f->overrideFileSetPermissions()

Returns true if a file has custom permissions set on it that override any file sets it happens to be in (only available when using advanced permissions.)

$f->setPermissions($obj, $canRead, $canSearch, $canWrite, $canAdmin)

Sets up a permissions record on the current File object. $obj may be an instance of the UserInfo or Group class. All arguments beginning with $can should be one of the following permissions levels:

	FilePermissions::PTYPE_NONE
FilePermissions::PTYPE_MINE
FilePermissions::PTYPE_ALL

$f->getUserID()

Returns the user ID of the user who created the File object.

$f->setUserID($uID)

Sets the user ID of the File object.

$sets = $f->getFileSets()

Gets an array containing all FileSet objects in which the current File object appears.

$r = $f->isStarred($u = false)

Returns true if the file is starred, checking against the $u User/UserInfo object if provided, otherwise using the currently logged-in User.

$f->getDateAdded()

Gets the date the file was added.

$fileVersion = $f->getVersionToModify($forceCreateNew = false)

Returns a file version object that is to be written to. Computes whether we can use the current most recent version, OR a new one should be created.

$f->getFileID()

Returns the current ID of the file.

$fv = $f->getApprovedVersion()

Returns the FileVersion object corresponding to the File's approved version.

$fv = $f->getRecentVersion()

Returns the most recent FileVersion object for this file.

$fv = $f->getVersion($fvID)

Returns a FileVersion object based on its FileVersion ID.

$r = $f->inFileSet(FileSet $fs)

Queries the FileSet $fs and returns true if the current file exists within it.

$f->delete()

Removes a file, including all of its versions. Unlinks all physical files from the storage location as well.

$fileVersions = $f->getVersionList()

Returns an array of all FileVersion objects owned by this file.

$r = $f->getDownloadStatistics()

Gets an associative array of download statistics for this file.

$f->trackDownload()

Increments the downloads table for the file, storing the currently logged-in user as the downloader.

FileVersion Object

The FileVersion object holds version-specific file data. Much of the data about files is, in fact, version-specific. For example, the same File object may hold completely different files, thumbnails, file types, etc... from one version to the next. For convenience, the File object will pass through any methods that it doesn't understand to its currently loaded FileVersion object.

Methods

$fv->getFileID()

Returns the file ID.

$fv->getFileVersionID()

Returns the file version ID.

$fv->getPrefix()

Returns the 12-digit numerical prefix which is used to store the file.

$fv->getFileName()

Returns the file's name.

$fv->getTitle()

Returns the title.

$fv->getTags()

Returns the tags.

$fv->getDescription()

Returns the file's description.

$fv->isApproved()

Returns true if the file version is approved.

$fv->getGenericTypeText()

Returns a text string corresponding to the file's type.

$f = $fv->getFile()

Gets the FileVersion's File object.

$tags = $fv->getTagsList()

Returns an array of tags by parsing line breaks.

$attributes = $fv->getAttributeList()

Returns an associative array of all attributes for a FileVersion object.

$fv->getAttribute($ak, $mode = false)

Returns an attribute. $ak may either be an AttributeKey object or AttributeKey text handle.

$fv->getMimeType()

Gets a file version's MIME type.

$fv->getSize()

Returns a file version's size in kilobytes.

$fv->getFullSize()

Returns the file size in bits.

$fv->getAuthorName()

Returns the username of the file version's author.

$fv->getAuthorUserID()

Returns the user ID of the file version's author.

$fv->getDateAdded($type= 'system')

Returns the date the File object was added. Specify 'user' for the type to convert the time into the user's timezone (ENABLE_USER_TIMEZONES must be enabled.)

$fv->getExtension()

Returns the extension of the file version.

$fv = $fv->duplicate()

Duplicates a file version, passing the new version back.

$fv->getType()

Gets the name of the file's type.

FileType $ft = $fv->getFileTypeObject()

Returns a FileType object for the current FileVersion.

$comments = $fv->getVersionLogComments()

Returns an array containing human-readable descriptions of everything that happened in this version

$fv->updateTitle($title)

Updates the title of the current File version.

$fv->updateTags($tags)

Updates the tags of the current File version.

$fv->updateDescription($description)

Updates the description of the current File version.

$fv->updateFile($filename, $prefix)

Updates the file of the current file version.

$fv->setAttribute($ak, $value)

Sets an attribute. $ak may be an instance of the AttributeKey object or an AttributeKey text handle.

$fv->delete()

Deletes a version of a file. Note, does NOT remove the physical file.

$path = $fv->getPath()

Returns a full filesystem path to the file on disk.

$url = $fv->getURL()

Returns a full URL to the file on disk.

$url = $fv->getDownloadURL()

Returns a URL that can be used to download the file. This passes through the download_file single page, which checks passwords, permissions, etc...

$url = $fv->getForceDownloadURL()

Returns a URL that can be used to download the file, and forces the download, i.e. images and PDFs won't attempt to display in-browser, they will always download. Also passes through the download_file single page, which checks passwords, permissions, etc...

$path = $fv->getRelativePath()

Gets a relative path to a file.

$path = $fv->getThumbnailPath($level)

Gets a full system path to a thumbnail. $level may be 1, 2 or 3.

$src = $fv->getThumbnailSRC($level)

Gets a relative path to a thumbnail. $level may be 1, 2 or 3.

$r = $fv->hasThumbnail($level)

Returns true if the FileVersion object has a thumbnail of that level.

$r = $fv->getThumbnail($level, $fullImageTag = true)

Returns a thumbnail if one is present, or a link to the file type's icon.

$fv->canView()

Returns true if this FileVersion's file type has a custom file viewer available to it (see the Metadata, Viewing & Editing section.)

$fv->canEdit()

Returns true if this FileVersion's file type has a custom file editor available to it (see the Metadata, Viewing & Editing section.)

Loading Conversation