Implements an iterator over the $_FILES super-global or an array of similar structure.

Abstracts differences in $_FILES format, throws exceptions when abnormal situations arise, and provides objects to work with the uploaded file.

package Haldayne

 Methods

Create a new UploadIterator.

__construct(array $input = null
API

With no arguments, creates an iterator over the $_FILES super-global. You may instead pass your own array having the same format as $_FILES. If any of the files indicate a security concern or a server problem that prevented their storage, then the constructor throws an exception.

api
since 1.0.0

Parameters

$input

array

An alternate $_FILES-like array to iterate over.

Exceptions

\Haldayne\Customs\UploadException

Return a count of upload entities within the iterator.

count() : integer
API
api
since 1.0.0

Returns

integer

Returns the current upload entity within the iterator.

current() : \Haldayne\Customs\UploadFile | \Haldayne\Customs\UploadError
API
api
since 1.0.0

Returns

\Haldayne\Customs\UploadFile\Haldayne\Customs\UploadError

Returns the key of the current upload entity within the iterator.

key() : integer
API
api
since 1.0.0

Returns

integer

Advance the iterator to the next upload entity.

next() : void
API
api
since 1.0.0

Rewind to the first element of the iterator.

rewind() : void
API
api
since 1.0.0

Arbitrarily move the current position within the iterator.

seek(integer $position) : void
API
api
since 1.0.0

Parameters

$position

integer

The position to access.

Exceptions

\OutOfBoundsException

Check if the current position within the iterator is valid.

valid() : boolean
API
api
since 1.0.0

Returns

boolean

Given an HTML name, gather all its information into a standard info structure.

gather(string $name) : array

Parameters

$name

string

Returns

array

Import a structure purporting to be a valid $_FILES format into a flat array of UploadFile or UploadError. Resolve all recursive structure and reconstitue the HTML form name.

import() 

Using the "name" key in the input as a model, figure out all the HTML names given in the original input.

names() 

Helper to `names`, which recursively traverses the iterator appending new keys onto the base-so-far.

reducer(\RecursiveArrayIterator $it, string $base, array $names) 

Parameters

$it

\RecursiveArrayIterator

$base

string

$names

array

Wrap the file upload information in an appropriate object class, raising an exception if one would be warranted by the error.

wrap(string $name, array $info) : \Haldayne\Customs\UploadFile | \Haldayne\Customs\UploadError

Parameters

$name

string

The HTML form element name

$info

array

The file upload information

Exceptions

\Haldayne\Customs\UploadException

Returns

\Haldayne\Customs\UploadFile\Haldayne\Customs\UploadError

 Properties

 

The internal array holding processed upload entities

$files : array

Default

 

The pointer to the current index in the internal array

$index : integer

Default

 

The $_FILES or similar array provided in ctor

$input : array

Default