Creates an object representing an uploaded file.
uploadfile Object
At first you need to instantiate an uploadfile-object. After that you can use the further functions (see below).
Syntax
To create a new uploadfile object:
uploadfile(string $field): ?hublify_var_ext_uploadfile
Parameter
- $field
The HTML-input-name.
Return
Returns the uploadfile-object for for field $field.
Example
{# Get upload file object, for INPUT-field "myUploadField" #}
{% set myFile = hublify.uploadfile('myUploadField') %}
...
Functions
Once you have an uploadfile-object, you can use following functions on it.
getInfo()
Returns detailed infos of the file.
Syntax
function getInfo(): array
Example
{# Get upload file object, for INPUT-field "myUploadField" #}
{% set myFile = hublify.uploadfile('myUploadField') %}
{% set result = myFile.getInfo() %}
-- result structure (example) --
[
[status] => true
[data] => [
[extension] => csv // file-extension, from the name.
[size] => 2350 // file-size in byte
[MimeType] => text/csv //
[ImageSize] - array Only available if is an image-file!
[height] - int The height in pixel.
[width] - int The width in pixel.
]
]
moveToMAM(...)
Move a file into the Hublify MAM as an asset.
Syntax
moveToMAM(?string $mam_dir = null, ?string $assetLabel = null): array
- $mam_dir
Optional sub-directory-path within Hublify-MAM. - $assetLabel
Optional asset-label under which to index it within MAM. (This is not the filename!)
If this asset-label already exists the asset will be overridden in the MAM.
Example
{# Get upload file object, for INPUT-field "myUploadField" #} {% set myFile = hublify.uploadfile('myUploadField') %} {# Let Hublify store the uploaded file in the MAM. Into directory: "my-sub-dir/", Forcing own label: "abc" #} {% set result = myFile.moveToMAM('my-sub-dir', 'abc') %}
importToDataboxTable(...)
Imports an uploaded file (CSV) into a databox-table.
Databox-Tables can easily accessed and worked with by Hublify-App users.
Syntax
importToDataboxTable(?string $as_label = null, ?array $params = null): array
- $as_label
A databox-table-label. This identifies into which databox-table the data will be imported.
If not given a random one is generated.
The necessary databox-table's fields (columns) are automatically created! :) - $params
Optional parameters, such as:- "existingData"- string Defines how possible existing data in a databox-table shall be treated or how the new data should be imported. Possible values are:
- "append" (default) - Old records are kept. The imported ones are added as new records, always.
- "truncate" - The databox-table is cleared beforehand.
- "skip" - Aborts the import if already any data-records are present in databox-table.
- "existingData"- string Defines how possible existing data in a databox-table shall be treated or how the new data should be imported. Possible values are:
Example
{# Get upload file object, for INPUT-field "myCSVUploadField" #}
{% set myFile = hublify.uploadfile('myCSVUploadField') %}
{# Run import of file. See result for details. #}
{% set result = myFile.importToDataboxTable('my_databox_i_want') %}
Examples
Simple, from a direct form
{% set myFileObj = hublify.uploadfile('myFormUploadFieldLabel') %} do further processing with myFileObj...