File Upload

Used to handle and query the status of a file upload.


initialise

string file_upload.initialise( )

Generate a unique key for file uploads.

Return Values

Returns an array with a single entry:

Name

Type

Description

key

string

Unique ID for the file to be uploaded



handle

void file_upload.handle( string key )

Uploads a file to the server.

Parameters

key

The unique key identifying the file upload element.

Return Values

Null / Void



inspect

array file_upload.inspect( string key )

Inspects the uploaded file specified by the key parameter. Returns information about the file.

Parameters

key

The unique key identifying the file upload element.

Return Values

Returns an array of details about the file.

Name

Type

Description

basename

string

Name of the file without any path information

extension

string

The file extension

filename

string

The name of the file without the extension

line_count

int

The number of lines in the CSV

size

integer

The size of the file in bytes

mime_type

string

The files mime-type as specified by the called client



inspectCsv

array file_upload.inspectCsv( string key, array csvOptions, integer maxRows )

Inspects an uploaded CSV or zipped CSV file. Similar result to #inspect, but supplemented with information about the CSV data.

Parameters

key

The unique key identifying the file upload element.

csvOptions

Associative array:

Key

Required

Type

Description

has_headers

Yes

boolean

Specifies whether the first row describes the columns

delimiter

No

char

The CSV data's field separator character. Defaults to comma

enclosure

No

char

The CSV data's text enclosing character. Defaults to double quote

maxRows

The maximum number of rows to return as sample data. The default is 5.

Return Values

Returns an associative array, see #inspect for structure.

Additional keys line_count and data are also returned, respectively containing a count of the number of records in the file, and an indexed array of associative arrays for sample CSV data:

data

Key

Type

Comment

columnId

int

Column number, zero-start

columnName

string

Name of the column, dependant on csvOptions had hasHeaders

isEmail

bool

If the column is detected as containing an email address

examples

array

Indexed array of sample row data, zero-start

array(
    0 => array(
        'columnId'   => 0,
        'columnName' => 'Firstname',
        'isEmail'    => false,
        'examples'   => array(
            0 => 'Luke',
            1 => 'James',
            2 => 'Tom'
        )
    ),
    1 => array(
        'columnId'   => 1,
        'columnName' => 'Email Address',
        'isEmail'    => true,
        'examples'   => array(
            0 => 'luke@example.com',
            1 => 'james@example.org',
            2 => 'tom@example.net'
        )
    ),
    2 => array(
        'columnId'   => 2,
        'columnName' => 'Lastname',
        'isEmail'    => false,
        'examples'   => array(
            0 => 'Smith',
            1 => 'Jones',
            2 => 'Williams'
        )
    ),
    3 => array(
        'columnId'   => 3,
        'columnName' => 'Sales Contact',
        'isEmail'    => true,
        'examples'   => array(
            0 => 'john@sales.example.co.uk',
            1 => 'john@sales.example.co.uk',
            2 => 'ian@sales.example.co.uk'
        )
    )
);

Service

file_upload

Methods