UNA
|
Public Member Functions | |
genToken ($iFileId) | |
changeStorageEngine ($sEngine) | |
isAvailable () | |
isInstalled () | |
getObject () | |
getObjectData () | |
getErrorCode () | |
getErrorString () | |
getMaxUploadFileSize ($iProfileId) | |
storeFile ($sMethod, $aMethodParams, $sName=false, $isPrivate=true, $iProfileId=0, $iContentId=0) | |
convertMultipleFilesArray ($aFiles) | |
storeFileFromForm ($aFile, $isPrivate=true, $iProfileId=0, $iContentId=0) | |
storeFileFromXhr ($sName, $isPrivate=true, $iProfileId=0, $iContentId=0) | |
storeFileFromPath ($sPath, $isPrivate=true, $iProfileId=0, $iContentId=0) | |
storeFileFromUrl ($sUrl, $isPrivate=true, $iProfileId=0, $iContentId=0) | |
storeFileFromStorage ($aParams, $isPrivate=true, $iProfileId=0, $iContentId=0) | |
deleteFile ($iFileId, $iProfileId=0) | |
queueFilesForDeletion ($mixedFileId) | |
queueFilesForDeletionFromGhosts ($iProfileId, $iContentId=false) | |
queueFilesForDeletionFromObject () | |
download ($aFile, $sToken=false, $bForceDownloadDialog='auto') | |
setFilePrivate ($iFileId, $isPrivate=true) | |
getFileUrlByRemoteId ($sRemoteId) | |
getFileUrlById ($iFileId) | |
getFile ($iFileId) | |
getGhost ($iFileId) | |
isFilePrivate ($iFileId) | |
afterUploadCleanup ($mixedFileIds, $iProfileId, $iContentId=false) | |
getGhosts ($iProfileId, $iContentId=false, $isCheckAllAccountProfiles=false, $isAdmin=false) | |
reorderGhosts ($iProfileId, $iContentId, $aGhosts) | |
updateGhostsContentId ($mixedFileIds, $iProfileId, $iContentId, $isAdmin=false) | |
getFiles ($iProfileId) | |
getFilesAll ($iStart=0, $iPerPage=1000) | |
getRestrictionsTextExtensions ($iProfileId) | |
getAllowedExtensions () | |
getRestrictionsTextFileSize ($iProfileId) | |
getRestrictionsTextArray ($iProfileId) | |
reloadMimeTypesFromFile ($sFile) | |
getFileExt ($sFileName) | |
getFileTitle ($sFileName) | |
getMimeTypeByFileName ($sFileName) | |
getIconNameByFileName ($sFileName) | |
getFontIconNameByFileName ($sFileName) | |
insertGhost ($iFileId, $iProfileId, $iContentId=0) | |
onBeforeFileDelete ($aFileInfo, $iProfileId) | |
onFileDeleted ($aFileInfo, $iProfileId, $aGhost=false) | |
queueFiles ($aFiles) | |
Static Public Member Functions | |
static | getObjectInstance ($sObject) |
static | pruning () |
static | pruneDeletions () |
static | isQueuedFilesForDeletion ($sPrefix) |
Protected Member Functions | |
__construct ($aObject) | |
determineIcon ($aIcons, $sExt, $sMimeType) | |
onBeforeFileAdd ($aFileInfo) | |
onFileAdded ($aFileInfo) | |
setErrorCode ($i) | |
genRandName ($isCheckForUniq=true) | |
genPath ($s, $iLevels) | |
genRemoteNamePath ($sPath, $sLocalId, $sExt) | |
isValidExt ($sExt) | |
isAllowedExt ($sExt) | |
isDeniedExt ($sExt) | |
isAllowedDeniedExt ($sExt, $sExtMode) | |
getFileDuration ($sFilePath, $sMimeType, $sExt, $oStorage) | |
getFileDimensions ($sFilePath, $sMimeType, $sExt, $oStorage) | |
isAuthUrl ($aFile) | |
Protected Attributes | |
$_aObject | |
$_iCacheControl | |
$_aParams | |
$_iErrorCode | |
$_oDb | |
$_aMimeTypesViewable = ['audio/', 'image/', 'video/'] | |
This class unify storage. As the result there are many advantages:
Usage.
Step 1: Add record to 'sys_objects_storage' table, like you doing this for Comments or Voting objects:
Step 2: Create table for files.
You need to enter this table name in 'table_files' field in 'sys_objects_storage' table, mentioned in step 1. The files will be added to this table automatically, all you need is to save 'id' from this table, so you can refer to the file by the 'id'. It is not recommended to change this table, it is better to create another table which will be connected with this one by file 'id'.
Step 3: Handling upload.
Sample HTML form:
Add server code in sample store_file.php file:
Please refer to the functions definition for more additional description of functions params.
Step 4: Displaying the file.
Use the following code to retrieve saved file. Remember you saved filed id somewhere in the previous step. Lets assume that the uploaded file is image, then we can show it using the following code:
It will show the file, regardless if it is private or public. You need to control it by yourself who will view the file. The difference in viewing private files is that link to the file is expiring after N seconds, you control this period using 'token_life' field in 'sys_objects_storage' table.
|
protected |
constructor
Reimplemented in BxDolStorageLocal, and BxDolStorageS3.
BxDolStorage::afterUploadCleanup | ( | $mixedFileIds, | |
$iProfileId, | |||
$iContentId = false ) |
Call this function after saving/associate just uploaded file id, so file is not orphaned/ghost. Ghost files appear on download form automaticaly during next upload, for example if file was uploaded but was not submitted for some reason. This mechanism ensure that the file is not lost.
$mixedFileIds | array of file ids or just one file id |
$iProfileId | profile id |
return | number of deleted ghost files |
BxDolStorage::changeStorageEngine | ( | $sEngine | ) |
Change storage engine. It's possible to change it when there is no files in storage engine.
$sEngine | new storage engine |
BxDolStorage::convertMultipleFilesArray | ( | $aFiles | ) |
convert default multiple files array into more logical one
BxDolStorage::deleteFile | ( | $iFileId, | |
$iProfileId = 0 ) |
Delete file by file id.
BxDolStorage::download | ( | $aFile, | |
$sToken = false, | |||
$bForceDownloadDialog = 'auto' ) |
Download file.
array | $aFile | downloading file info. |
boolean | $bForceDownloadDialog | if downloading to a local file system first is required and/or send the outout as attachment rather than inline. |
Reimplemented in BxDolStorageLocal, and BxDolStorageS3.
BxDolStorage::genToken | ( | $iFileId | ) |
Get file token for private files.
$iFileId | file |
BxDolStorage::getAllowedExtensions | ( | ) |
BxDolStorage::getErrorCode | ( | ) |
Get error code from the last occured error
BxDolStorage::getErrorString | ( | ) |
Get error string from the last occured error
BxDolStorage::getFile | ( | $iFileId | ) |
Get file info array by file id.
$iFileId | file id |
BxDolStorage::getFileExt | ( | $sFileName | ) |
Get file extension by file name.
$sFileName | file name |
BxDolStorage::getFiles | ( | $iProfileId | ) |
Get files list for particular user.
$iProfileId | profile id |
BxDolStorage::getFilesAll | ( | $iStart = 0, | |
$iPerPage = 1000 ) |
Get all files in the storage
BxDolStorage::getFileTitle | ( | $sFileName | ) |
Get file title by file name, actually file title is file name without extension.
$sFileName | file name |
BxDolStorage::getFileUrlById | ( | $iFileId | ) |
Get file url.
$iFileId | file id |
Reimplemented in BxDolStorageLocal, BxDolStorageS3, and BxDolStorageS3v4alt.
BxDolStorage::getFileUrlByRemoteId | ( | $sRemoteId | ) |
Get file url.
$sRemoteId | file remote id |
BxDolStorage::getFontIconNameByFileName | ( | $sFileName | ) |
Get file font icon by file name. Actually just a class name of icon is returnted.
$sFileName | file name |
BxDolStorage::getGhost | ( | $iFileId | ) |
Get ghost file info array by file id.
$iFileId | file id |
BxDolStorage::getGhosts | ( | $iProfileId, | |
$iContentId = false, | |||
$isCheckAllAccountProfiles = false, | |||
$isAdmin = false ) |
Get ghost/orphaned files for particular user.
$iProfileId | profile id |
$iContentId | content id, or false to not consider content id at all |
$isCheckAllAccountProfiles | get all files associated with all account profiles |
$isAdmin | if true, then don't check files ownership, it makes sense when $iContentId is provided, so it will return all files assiciated with content |
BxDolStorage::getIconNameByFileName | ( | $sFileName | ) |
Get file icon by file name. File icon is just icon filename without patch or URL. File icons must be located in images/icons directory in your template subfolder.
$sFileName | file name |
BxDolStorage::getMaxUploadFileSize | ( | $iProfileId | ) |
Get max file size allowed for current user, it checks user quota, object quota, site quota and php setting
$iProfileId | profile id to check quota for |
BxDolStorage::getMimeTypeByFileName | ( | $sFileName | ) |
Get file mime/type by file name.
$sFileName | file name |
|
static |
Get storage object instance by object name
$sObject | object name |
Implements iBxDolFactoryObject.
BxDolStorage::getRestrictionsTextArray | ( | $iProfileId | ) |
Get readable representation of all restrictions.
$iProfileId | profile id |
BxDolStorage::getRestrictionsTextExtensions | ( | $iProfileId | ) |
Get readable representation of restrictions by file extentions.
$iProfileId | profile id |
BxDolStorage::getRestrictionsTextFileSize | ( | $iProfileId | ) |
Get readable representation of restrictions by file size.
$iProfileId | profile id |
BxDolStorage::isAvailable | ( | ) |
Is storage engine available?
BxDolStorage::isFilePrivate | ( | $iFileId | ) |
check if file is private or public
$iFileId | file id |
BxDolStorage::isInstalled | ( | ) |
Are required php modules installed for this storage engine ?
|
static |
Check if module has any files pending for deletion, it is supposed that all module storage object names are prefixed with module name
$sPrefix | - usually module name |
|
static |
Delete files queued for deletions It is alutomatically called upin cron execution, usually one time per minute. Max number of deletetion per time is defined in
|
static |
Delete old security tokens from database. It is alutomatically called upin cron execution, usually once in a day.
BxDolStorage::queueFilesForDeletion | ( | $mixedFileId | ) |
Queue file(s) for deletion. File(s) will be deleted later upon cron call (usually every minute).
$mixedFileId | file id or array of file ids. |
BxDolStorage::queueFilesForDeletionFromGhosts | ( | $iProfileId, | |
$iContentId = false ) |
Queue file(s) for deletion by getting neccesary files from ghosts table by profile id and content id
$iProfileId | profile id associated with files |
$iContentId | content id associated with files, or false if to check by profile id only |
BxDolStorage::queueFilesForDeletionFromObject | ( | ) |
Queue file(s) for deletion of the whole storage object
BxDolStorage::reloadMimeTypesFromFile | ( | $sFile | ) |
Reread available mimetypes from particular file. It clears 'sys_storage_mime_types' table and fill it with data form provided file. The format of file is: mime/type space_or_tab extentions_sperated_by_space. Usually the file is mime.types file from apache or /etc/mime.types from unix systems.
$sFile | file to read mime types from |
BxDolStorage::reorderGhosts | ( | $iProfileId, | |
$iContentId, | |||
$aGhosts ) |
Reorder ghost/orphaned files for particular content/user.
$iProfileId | profile id |
$iContentId | content id, or false to not consider content id at all |
$aGhosts | an ordered list of ghost/orphaned files' IDs. |
BxDolStorage::setFilePrivate | ( | $iFileId, | |
$isPrivate = true ) |
Set file private or public.
Reimplemented in BxDolStorageS3, and BxDolStorageS3v4alt.
BxDolStorage::storeFile | ( | $sMethod, | |
$aMethodParams, | |||
$sName = false, | |||
$isPrivate = true, | |||
$iProfileId = 0, | |||
$iContentId = 0 ) |
Store file in the storage area. It is not recommended to use this function directly, use other funtions like: storeFileFromForm, storeFileFromXhr, storeFileFromPath, storeFileFromUrl
$sMethod | upload method, like regular Form upload, upload from URL, etc |
$aMethodParams | upload method params |
$sName | file name with extention |
$isPrivate | private or public file |
$iProfileId | profile id of the upload action performer |
$iContentId | content id to associate with ghost file |
BxDolStorage::storeFileFromForm | ( | $aFile, | |
$isPrivate = true, | |||
$iProfileId = 0, | |||
$iContentId = 0 ) |
the same as storeFile, but it tries to do it directly from uploaded file
BxDolStorage::storeFileFromPath | ( | $sPath, | |
$isPrivate = true, | |||
$iProfileId = 0, | |||
$iContentId = 0 ) |
the same as storeFile, but it tries to do it directly from local file
BxDolStorage::storeFileFromStorage | ( | $aParams, | |
$isPrivate = true, | |||
$iProfileId = 0, | |||
$iContentId = 0 ) |
the same as storeFile, but it tries to do it directly from the same or another storage by file id
$aParams['id'] | - file ID in the storage |
$aParams['storage'] | - the storage name |
BxDolStorage::storeFileFromUrl | ( | $sUrl, | |
$isPrivate = true, | |||
$iProfileId = 0, | |||
$iContentId = 0 ) |
the same as storeFileFromPath, but it tries to do it from URL
BxDolStorage::storeFileFromXhr | ( | $sName, | |
$isPrivate = true, | |||
$iProfileId = 0, | |||
$iContentId = 0 ) |
the same as storeFile, but it tries to do it directly from HTML5 file upload method
BxDolStorage::updateGhostsContentId | ( | $mixedFileIds, | |
$iProfileId, | |||
$iContentId, | |||
$isAdmin = false ) |
Update ghosts' content id.
$mixedFileIds | array of file ids or just one file id |
$iProfileId | profile id |
$iContentId | content id |
$isAdmin | if true, then don't check files ownership |