ze\fileAdm::addToDatabase()
ze\fileAdm::addToDatabase($usage, $location, $filename = false, $mustBeAnImage = false, $deleteWhenDone = false, $addToDocstoreDirIfPossible = false, $imageAltTag = false, $imageTitle = false, $imagePopoutTitle = false, $imageMimeType = false, $imageCredit = '', $setPrivacy = null)
You can add a new file into the files table of the CMS using this function.
You can use this function to insert new records to the files table in the CMS.
Note that the files table has a key on usage and checksum. If you attempt to add a file that is identical to an existing file in the table, the file will not be added and this function will return the id of the existing file.
If two identical files with different names are uploaded, only one will be stored and only one name will be kept. If the filename is important to you then you should store it separately.
$usage
The code name of the library the file is going into, e.g. content, documents, hierarchical_file, image, site_setting...
$location
The path to the file's current location. (E.g. this will probably be in the temporary directory if you are dealing with an uploaded file). If you're saving a file from the $_FILES variable in PHP, then this is $_FILES['input_name_here']['tmp_name'].
$filename
The name you wish the file to have, if different from its current name.
$mustBeAnImage
Set this to true if you want the uploaded file to be an image. The CMS will then reject any non-images and this function will return false.
$deleteWhenDone
Should the CMS attempt to delete the source file from the file system when done?
$addToDocstoreDirIfPossible
Should the CMS attempt to add this file to the docstore directory rather than the database? In general, you should set this to true for uses that are usually large in size, such as raw pictures and videos, and false for uses that are usually small in size, such as inline images. Note that if the docstore directory is not set up on a site, this function will then attempt to add a file to the database as a fallback.
Returns the id of the file in the files table, or false if the file could not be added.