Brain’s Upload class allows for uploading of files to the server filesystem, database, or to be handed off to SFTP for storage on a different server. Configuration options are similar to CodeIgniter’s upload config, but there are substantial differences.


Sample upload configuration can be found in config/upload.php for each of the three upload types. By default, the upload type is for filesystem storage, but a “driver” can be specified in the config array. “database” and “sftp” are to be used when the upload type is not “filesystem”. If files are to be stored in the database, the table used for uploads is specified in config/db.php.

The success_callback Config Option

When a file is successfully uploaded, we’ll normally want to do something. Just uploading the file doesn’t mean much if we don’t store it’s location in the database, or output the image somehow. For that reason, we use an anonymous function to handle what is done. The sole parameter to the anonymous function is $obj, which is the object of the specific upload type that was done, complete with information about the upload. If you need to output something to the browser, or pass something back to the controller, this is a good place to set a config item. I’ve used a config item named “callback_output” in each of my examples when testing the three upload types.


Usage for all three upload types is very similar.

// If filesystem upload type
$u = $this->container['upload'];

// If database upload type
$u = $this->container['db_upload'];

// If SFTP upload type
$u = $this->container['sftp_upload'];

if( ! empty( $_FILES ) )