Search by

files.com / files-php-sdk

Files.com

Files.com PHP SDK

Package info

github.com/Files-com/files-sdk-php

Homepage

pkg:composer/files.com/files-php-sdk

Statistics

Installs: 89 466

Dependents: 0

Suggesters: 0

Stars: 24

Open Issues: 0

v2.0.788 2026-12-05 21:57 UTC

This package is auto-updated.

Last update: 2026-12-05 21:59:18 UTC


README

The Files.com PHP SDK lets PHP applications manage files, folders, users, and other resources through the Files.com API.

The developer documentation provides the complete API reference and additional guides for integrating the SDK into your application.

Introduction

For integration choices and credential scope, start with SDKs & APIs. Scripts, APIs & Application Workflows explains how to coordinate Files.com operations with the work your application owns.

The Files.com PHP SDK gives your application access to file and folder operations as well as administrative tasks, such as adding or removing users, onboarding partners and retrieving information about Automations.

Installation

The PHP SDK is distributed through Packagist and installed with Composer.

First, install Composer if necessary:

curl -sS https://getcomposer.org/installer | php

Then use Composer to install the Files.com SDK:

php composer.phar require files.com/files-php-sdk

Requirements

  • PHP 5.5+
  • php-curl extension

Explore the files-sdk-php code on GitHub.

Getting Support

The Files.com Support team provides official support for all of our official Files.com integration tools.

To initiate a support conversation, you can send an Authenticated Support Request or simply send an E-Mail to support@files.com.

Authentication

There are two ways to authenticate: API Key authentication and Session-based authentication.

Authenticate with an API Key

Authenticating with an API key is the recommended authentication method for most scenarios, and is the method used in the examples on this site.

To use an API Key, first generate an API key from the web interface or via the API or an SDK.

A user key follows its account's permissions, narrowed by the key's permission scope, Workspace, and any path restriction on file operations. It can perform administrative operations only when both the account and key permit them. API Keys explains credential scope and lifecycle; Workspaces explains request context and delegated administration.

\Files\Files::setApiKey('YOUR_API_KEY');

try {
  # Alternatively, you can specify the API key on a per-object basis in the second parameter to a model constructor.
  $user = new \Files\Model\User($params, array('api_key' => 'YOUR_API_KEY'));

  # You may also specify the API key on a per-request basis in the final parameter to static methods.
  \Files\Model\User::find($id, $params, array('api_key' => 'YOUR_API_KEY'));

  # An api_key given either way is used instead of a session set with setSessionId().
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Don't forget to replace the placeholder, YOUR_API_KEY, with your actual API key.

Authenticate with a Session

Create a session with the username and password of an active user. The session uses that user's permissions, including any delegated administrative access. Workspaces describes account scope and administrative access.

Sessions use the same timeout settings as sessions in the web interface. When a session expires, create a new one and use it to authenticate subsequent SDK calls. The SDK does not renew sessions automatically because doing so would require keeping your password in memory without your explicit consent.

Logging In

To create a session, call \Files\Model\Session::create() with the user's username and password. The returned session object can be used to authenticate subsequent SDK calls.

try {
  $session = \Files\Model\Session::create(['username' => 'motor', 'password' => 'vroom']);
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Using a Session

Once you have created a session, you can configure it globally or use it to authenticate a particular object or request.

## You may set the returned session ID to be used by default for subsequent requests.
\Files\Files::setSessionId($session->id);

try {
  # Alternatively, you can specify the session ID on a per-object basis in the second parameter to a model constructor.
  $user = new \Files\Model\User($params, array('session_id' => $session->id));

  # You may also specify the session ID on a per-request basis in the final parameter to static methods.
  \Files\Model\User::find($id, $params, array('session_id' => $session->id));

  # A session_id given either way is used before an api_key given with it, and an api_key given either way instead of
  # the session set with setSessionId(); without either, that session is used before the API key set with setApiKey().
  # One that PHP reads as false (null, '', 0, '0', false) is ignored.
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Logging Out

User sessions can be ended by calling the Session::destroy method.

try {
  \Files\Model\Session::destroy();
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Configuration

Configure the PHP SDK globally by setting properties directly on the \Files\Files class.

Use the headers request option for integration metadata. Do not put API keys, passwords, or other credentials in it. Use the SDK's api_key or session_id settings for Files.com authentication.

Configuration Options

Auto Paginate

When true, list methods such as Folder::listFor() fetch every page and return one array; when false, they return only the first page. The default value is true. Page methods such as Folder::listForPage() fetch one page at a time, whatever this setting is; see Pagination.

\Files\Files::$autoPaginate = false

Base URL

Setting a base URL is optional for most sites. Use your site's full HTTPS address, such as https://MY-SUBDOMAIN.files.com, to identify the site even when authentication fails. This allows those failures to appear in your site's API logs. Without a site-specific URL, Files.com cannot associate an authentication failure with your site or record it in those logs.

You must set a site-specific base URL if your site has global acceleration disabled. You can also point the SDK at a mock server for development or CI.

\Files\Files::setBaseUrl('https://MY-SUBDOMAIN.files.com');

Log Level

Supported values:

  • \Files\LogLevel::NONE
  • \Files\LogLevel::ERROR
  • \Files\LogLevel::WARN
  • \Files\LogLevel::INFO (default)
  • \Files\LogLevel::DEBUG
\Files\Files::$logLevel = \Files\LogLevel::DEBUG

Debug Requests

Enable debug logging of API requests. The default value is false.

\Files\Files::$debugRequest = true

Debug Response Headers

Enable debug logging of API response headers. The default value is false.

\Files\Files::$debugResponseHeaders = true

Connect Timeout

Network connect timeout in seconds. The default value is 30.0.

\Files\Files::$connectTimeout = 20.0

Read Timeout

Network read timeout in seconds. The default value is 60.0.

\Files\Files::$readTimeout = 60

Minimum Retry Delay

Minimum network delay in seconds before retrying. The default value is 0.5.

\Files\Files::$minNetworkRetryDelay = 1.0

Maximum Retry Delay

Maximum network delay in seconds before retrying. The default value is 1.5.

\Files\Files::$maxNetworkRetryDelay = 3.0

Maximum Network Retries

Maximum number of retries. The default value is 3.

\Files\Files::$maxNetworkRetries = 5

Sort and Filter

Several of the Files.com API resources have list operations that return multiple instances of the resource. The List operations can be sorted and filtered.

Sorting

To sort the returned data, pass in the sort_by method argument.

Each resource supports a unique set of valid sort fields and can only be sorted by one field at a time.

Use a PHP associative array with the field name as its key and "asc" or "desc" as its value.

Folder Listing Order

Folder listings always place folders before files, regardless of the requested sort order. The sort parameters apply within each group. This preserves compatibility with the folder-first order used by other file-transfer and file-sharing services.

try {
  // users sorted by username
  $users = \Files\Model\User::list(array(
    'sort_by' => array("username" => "asc")
  ));
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Filtering

Filters apply selection criteria to the underlying query that returns the results. They can be applied individually or combined with other filters, and the resulting data can be sorted by a single field.

Each resource supports a unique set of valid filter fields, filter combinations, and combinations of filters and sort fields.

Use a PHP associative array with the field name as its key and the comparison value as its value.

Filter Types

Filter Type Description
filter Exact Find resources that have an exact field value match to a passed in value. (i.e., FIELD_VALUE = PASS_IN_VALUE).
filter_prefix Pattern Find resources where the specified field is prefixed by the supplied value. This is applicable to values that are strings.
filter_gt Range Find resources that have a field value that is greater than the passed in value. (i.e., FIELD_VALUE > PASS_IN_VALUE).
filter_gteq Range Find resources that have a field value that is greater than or equal to the passed in value. (i.e., FIELD_VALUE >= PASS_IN_VALUE).
filter_lt Range Find resources that have a field value that is less than the passed in value. (i.e., FIELD_VALUE < PASS_IN_VALUE).
filter_lteq Range Find resources that have a field value that is less than or equal to the passed in value. (i.e., FIELD_VALUE <= PASS_IN_VALUE).
try {
  // non admin users
  $users = \Files\Model\User::list(array(
    'filter' => array("not_site_admin" => true)
  ));

  foreach ($users as $value) {
    print("User username: " . $value->getUserName() . "\n");
  }
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}
try {
  // users who have logged in on or after 2024-01-01
  $users = \Files\Model\User::list(array(
    'filter_gteq' => array("last_login_at" => "2024-01-01")
  ));

  foreach ($users as $value) {
    print("User username: " . $value->getUserName() . "\n");
  }
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}
try {
  // users whose usernames start with 'test'
  $users = \Files\Model\User::list(array(
    'filter_prefix' => array("username" => "test")
  ));

  foreach ($users as $value) {
    print("User username: " . $value->getUserName() . "\n");
  }
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}
try {
  // users whose usernames start with 'test' and are not admins
  $users = \Files\Model\User::list(array(
    'filter_prefix' => array("username" => "test"),
    'filter' => array("not_site_admin" => true),
    'sort_by' => array("last_login_at" => "asc")
  ));

  foreach ($users as $value) {
    print("User username: " . $value->getUserName() . "\n");
  }
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Paths

Files.com preserves the spelling of file and folder paths while comparing them using shared case and Unicode rules. Use the SDK comparison helpers when matching paths locally.

Capitalization

Files.com uses case-insensitive path matching based on its fixed Unicode comparison map.

For example, the following paths have the same comparison key:

Path Variant Comparison Key
Documents/Reports/Q1.pdf documents/reports/q1.pdf
documents/reports/q1.PDF documents/reports/q1.pdf
DOCUMENTS/REPORTS/Q1.PDF documents/reports/q1.pdf

This behavior applies across:

  • API requests
  • Folder and file lookup operations
  • Automations and workflows

See also: Case Sensitivity Documentation

The PathUtil::same function in the Files.com SDK is designed to help you determine if two paths on your native file system would be considered the same on Files.com. This is particularly important when handling errors related to duplicate file names and when developing tools for folder synchronization.

if(\Files\Util\PathUtil::same("Fïłèńämê.Txt", "filename.txt")) {
    echo "Paths are the same\n";
}

Slashes

Use / between folder and file names, without leading or trailing slashes. SDK normalization helpers convert backslashes to /, remove duplicate separators, and discard exact . and .. components. Discarding .. leaves the preceding folder name intact.

Input Normalized path
folder/subfolder/file.txt folder/subfolder/file.txt
/folder/subfolder/file.txt folder/subfolder/file.txt
folder/subfolder/file.txt/ folder/subfolder/file.txt
//folder//file.txt folder/file.txt
folder/../file.txt folder/file.txt

Unicode and Path Comparison

Files.com compares paths using a fixed mapping shared by the server and SDKs. It treats case and many accent differences as equivalent: Résumé.txt and resume.txt identify the same file, as do q followed by a combining acute accent and q. The mapping also handles other equivalences, such as Hiragana and Katakana. Lowercasing or applying a standard Unicode normalization form alone does not reproduce these rules.

SDK comparison helpers normalize path separators and dot segments, then apply the bundled versioned comparison map. The shared examples give exact comparison results for integrations that implement their own matching. The map uses hexadecimal Unicode scalar values as keys: a missing entry preserves the character, an empty replacement removes it, and other replacements may contain several characters. Apply each replacement once without normalizing or lowercasing the result again.

Use comparison results only for matching. Send the original path spelling in API requests and preserve it for display and local filenames; comparison results can have a different spelling or length.

Trailing whitespace is significant for comparison. report.txt and report.txt are different file paths, and SDK helpers preserve spaces, tabs, and newlines. Folder names cannot end in whitespace. See Unicode Normalization for the complete path rules.

Workspaces

A Workspace groups files, users, groups, Partners, integrations, and workflows within a Files.com Site. An integration can provision a Workspace for a department or project and delegate its operation to a team without making that team Site Administrators. Every Site has a Default Workspace, with ID 0; additional Workspaces have their own IDs and root folders.

Account membership, request context, and permission grants serve different purposes. Creating an account in a Workspace determines where it belongs. Selecting a Workspace determines which resources a request operates on. A permission grant determines what the caller can do there. Selecting a Workspace never grants access to it.

Accounts and Administrative Access

A user's or group's workspace_id identifies the Workspace the account belongs to. Accounts belonging to a Custom Workspace stay within it. Default Workspace users and groups can receive permissions in one or more Custom Workspaces while keeping their existing accounts in Workspace 0.

Account Workspace Administrator assignment Scope
User belonging to a Custom Workspace Set the user's workspace_admin to true. That user's own Custom Workspace.
Default Workspace user Create an admin Permission for the user on a Custom Workspace's root folder. Each Custom Workspace with a root grant.
Default Workspace group Create an admin Permission for the group on a Custom Workspace's root folder. Every member inherits administration of each Workspace with a root grant.

workspace_admin is not a summary of a user's effective administrative access. A Default Workspace user can administer a Custom Workspace through a direct or group root grant while their workspace_admin remains false. Groups have no workspace_admin field. See Users and Groups for account fields.

An admin grant on the Custom Workspace root provides full Workspace Administrator authority over its files, users, groups, Partners, workflows, and integrations. An admin grant on a subfolder provides Folder Admin authority over that folder and its descendants; it does not provide Workspace administration. Other permission levels provide their corresponding folder access without Workspace administration. Permissions defines the levels.

Site Administrators manage cross-Workspace assignments to Default Workspace accounts. Workspace Administrators manage accounts and permissions within their own scope. Site Administrators retain access to every Workspace; adding a Workspace grant does not narrow Site Administrator authority. The product documentation explains the administrator's operational scope and site-wide controls.

Request Context and API Keys

You can include the X-Files-Workspace-Id REST header to select a Workspace for a request. SDK request options and CLI configuration send that same selection. When a Workspace is selected, Workspace-scoped resources are listed, created, and changed within that context, and ordinary paths are relative to its root.

A resource's workspace_id request field describes the resource's Workspace membership. It is separate from the SDK's Workspace request option or REST header. Creating a Workspace-scoped resource in a Custom Workspace defaults its workspace_id to the selected Workspace; a mismatching membership value is rejected with not-authorized/insufficient-permission-for-params.

Selecting another Workspace with an API key requires a Full Access key created in the Default Workspace. A user key follows that user's current access, including group permissions. A site-wide Full Access key created in the Default Workspace has Site Administrator authority in every Workspace. A Files Only key stays in its creation Workspace, even if its user has cross-Workspace access. Any key created in a Custom Workspace stays within that Workspace. Selecting another context with these confined keys is rejected with bad-request/invalid-workspace-id-header.

An account belonging to a Custom Workspace is scoped there when it authenticates normally. For a Default Workspace user, explicitly select the intended Workspace for an integration rather than relying on an interactive login preference. API Keys and Authentication cover credentials.

The Files.com PHP SDK supports workspace scoping by using the \Files\Files::setWorkspaceId configuration method. Scope a single request by passing workspace_id in the request options.

The adjacent scoping example uses a credential authorized for the selected Workspace. A group member uses their own Full Access user key from the Default Workspace; the Site Administrator credential used to assign the grant is not needed for their day-to-day work.

\Files\Files::setWorkspaceId(123);

\Files\Model\Folder::listFor("/", [], ["workspace_id" => 456]);

Delegating a Workspace to an Existing Group

An operations team already represented by a Default Workspace group can administer a Custom Workspace through one root Permission. The group and its members stay in the Default Workspace, so the same team can receive different access in other Workspaces.

First retrieve the target Workspace and Group IDs as a Site Administrator in Workspace 0. The examples use Workspace 123, group 456, and member user 789; replace them with your own IDs. Confirm that the group belongs to Workspace 0 and that the intended user is a member.

Create the Permission using a Default Workspace Full Access site-wide key or a Full Access user key belonging to a Site Administrator. Keep the request context at 0 and use the qualified root path _/Workspaces/123. Set group_id to the group's ID, permission to admin, and recursive to true. Save the returned Permission id for later removal. For an individual Default Workspace user, use user_id instead of group_id.

For a Default Workspace group, a Site Administrator can also select Workspace 123 and use an empty path to grant access to its root. The qualified path in Workspace 0 works for both Default Workspace users and groups and keeps the account scope and target Workspace explicit. Appending a subfolder to the path would grant Folder Admin access instead of Workspace Administrator authority.

After the grant, make a request as the member, using their own credential with Workspace 123 selected, such as listing that Workspace's root folder. That member can work with the Workspace's files and perform Workspace Administrator operations, such as managing its users, Partners, and integrations. A Site Administrator's successful request does not establish that the member has the intended access.

\Files\Files::setWorkspaceId(0);
$grant = \Files\Model\Permission::create([
    "path" => "_/Workspaces/123",
    "group_id" => 456,
    "permission" => "admin",
    "recursive" => true,
], ["workspace_id" => 0]);
echo $grant->getId();

Permission Inspection and Removal

List the member's Permissions with user_id and include_groups=true to include grants inherited through group membership. Listing only direct user grants can miss the Permission that provides Workspace administration. In Workspace 0, the Custom Workspace root appears as _/Workspaces/123; in Workspace 123, paths are relative to that root. Inspect the root path and permission=admin, rather than treating the user's workspace_admin field as their effective administrative access.

Permission lists show individual grants, rather than a single flag for effective administrative access. Membership in several groups combines their access. A Permission using group_ids instead of group_id requires membership in all the specified groups; it is not a shorthand for assigning the same grant to several independent groups.

Removing a member ends access received through that group. Deleting the root Permission ends the group's Workspace Administrator grant for every member. These changes leave independent direct and other group grants in place, so review all applicable grants when withdrawing access. Default Workspace user API keys follow those permission changes without being recreated.

Group membership maintained through SCIM follows the same rule. A Group Admin allowed to add members can give those users the group's existing Workspace Administrator access. Choose who manages the group with that authority in mind.

Delete the Permission by its returned id as the Site Administrator in Workspace 0. The removal examples use Permission ID 9001; replace it with the ID returned by your create request. Permissions are created and deleted, rather than updated in place. If narrower folder access is still needed, assign it explicitly; deleting a broad grant does not restore narrower grants it previously replaced.

$grants = \Files\Model\Permission::all([
    "user_id" => "789", "include_groups" => true,
], ["workspace_id" => 0]);
(new \Files\Model\Permission(["id" => 9001], ["workspace_id" => 0]))->delete();

Foreign Language Support

The Files.com PHP SDK supports localized responses by using the \Files\Files::setLanguage() configuration method. When configured, this guides the API in selecting a preferred language for applicable response content.

Language support currently applies to select human-facing fields only, such as notification messages and error descriptions.

If the specified language is not supported or the value is omitted, the API defaults to English.

\Files\Files::setLanguage('es');

Errors

The PHP SDK throws exceptions when an operation fails. SDK exceptions originate within the SDK, such as parameter validation or connection failures. API exceptions represent errors returned by the Files.com API and are grouped by error type. The exception class identifies the kind of failure.

For an HTTP error, getMessage() includes the request method, HTTP status and, for an API error, its type. It omits the response body and request URL because they can contain credentials. Transport error messages replace the URL with [redacted]. Use getError(), getTitle() and the other getters below for the API's error details.

Use standard PHP exception handling to respond to these errors. Catch the specific exception classes that need their own response first. You can then catch Files\Exception\FilesException to handle any remaining SDK or API exceptions.

try {
  $session = Files\Model\Session::create(['username' => 'USERNAME', 'password' => 'BADPASSWORD']);
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Error Types

SDK Errors

SDK errors are general errors that occur within the SDK code. These errors generate exceptions. Each of these exception classes inherit from a standard Exception base class.

The Api* exceptions below extend ApiConnectionException, which classifies how a request the SDK sent failed, apart from an API error: the API could not be reached, the HTTP client failed, the API answered with a 5xx status, or the SDK could not use the response.

Files\Exception\ApiConnectException ->
Files\Exception\ApiConnectionException ->
Files\Exception\FilesException ->
Exception
SDK Exception Classes
Exception Class Name Description
ApiConnectionException The parent of the Api* exceptions below
ApiBadResponseException The SDK could not use the response, such as an HTTP error status below 500 without a readable Files.com error object, a model that is not a JSON object, a list that is not a JSON array, or a list cursor that was already followed
ApiConnectException The Files.com API cannot be reached, or the request timed out
ApiRequestException The HTTP client could not complete the request, for example because of a TLS error
ApiServerException The API service answered with a 5xx status, whatever the response body holds
ApiTooManyRedirectsException The API service redirected too many times
ApiTransferException The HTTP client failed to transfer the request
ConfigurationException Invalid SDK configuration parameters
EmptyPropertyException A required property was empty
InvalidParameterException A passed in parameter is invalid
MissingParameterException A method parameter is missing
NotImplementedException The called method has not been implemented by the SDK

API Errors

Each API exception class inherits from a base class for its error group. This lets you catch a specific error or handle the broader category through the group's base class.

An HTTP error response with a status below 500 whose body is a Files.com error object raises the exception class its type names, or ApiException itself for a type the SDK does not recognize. The getters getType(), getError(), getTitle(), getHttpCode(), getDetail(), getErrors() and getData() return the error object's fields, or null for a field it does not include.

Files\Exception\NotAuthorized\FolderAdminPermissionRequiredException ->
Files\Exception\NotAuthorizedException ->
Files\Exception\ApiException ->
Files\Exception\FilesException ->
Exception
API Exception Classes
Exception Class Name Error Group
AgentUpgradeRequiredException BadRequestException
AttachmentTooLargeException BadRequestException
CannotDownloadDirectoryException BadRequestException
CantMoveWithMultipleLocationsException BadRequestException
DatetimeParseException BadRequestException
DestinationSameException BadRequestException
DestinationSiteMismatchException BadRequestException
DoesNotSupportSortingException BadRequestException
FolderMustNotBeAFileException BadRequestException
FoldersNotAllowedException BadRequestException
InternalGeneralErrorException BadRequestException
InvalidBodyException BadRequestException
InvalidCursorException BadRequestException
InvalidCursorTypeForSortException BadRequestException
InvalidEtagsException BadRequestException
InvalidFilterAliasCombinationException BadRequestException
InvalidFilterFieldException BadRequestException
InvalidFilterParamException BadRequestException
InvalidFilterParamFormatException BadRequestException
InvalidFilterParamValueException BadRequestException
InvalidInputEncodingException BadRequestException
InvalidInterfaceException BadRequestException
InvalidOauthProviderException BadRequestException
InvalidPathException BadRequestException
InvalidReturnToUrlException BadRequestException
InvalidSearchQueryException BadRequestException
InvalidSortFieldException BadRequestException
InvalidSortFilterCombinationException BadRequestException
InvalidUploadOffsetException BadRequestException
InvalidUploadPartGapException BadRequestException
InvalidUploadPartSizeException BadRequestException
InvalidWorkspaceIdHeaderException BadRequestException
MethodNotAllowedException BadRequestException
MultipleSortParamsNotAllowedException BadRequestException
NoValidInputParamsException BadRequestException
OffsetUploadNotAllowedWithMalwareScanningException BadRequestException
PartNumberTooLargeException BadRequestException
PathCannotHaveTrailingWhitespaceException BadRequestException
ReauthenticationNeededFieldsException BadRequestException
RequestBodyTooLargeException BadRequestException
RequestParamsContainInvalidCharacterException BadRequestException
RequestParamsInvalidException BadRequestException
RequestParamsRequiredException BadRequestException
SearchAllOnChildPathException BadRequestException
SearchQueryTooShortException BadRequestException
UnrecognizedSortIndexException BadRequestException
UnsupportedHttpResponseFormatException BadRequestException
UnsupportedMediaTypeException BadRequestException
UserIdInvalidException BadRequestException
UserIdOnUserEndpointException BadRequestException
UserRequiredException BadRequestException
AdditionalAuthenticationRequiredException NotAuthenticatedException
ApiKeySessionsNotSupportedException NotAuthenticatedException
AuthenticationRequiredException NotAuthenticatedException
BundleRegistrationCodeFailedException NotAuthenticatedException
InboxRegistrationCodeFailedException NotAuthenticatedException
InvalidCredentialsException NotAuthenticatedException
InvalidOauthException NotAuthenticatedException
InvalidOrExpiredCodeException NotAuthenticatedException
InvalidSessionException NotAuthenticatedException
InvalidUsernameOrPasswordException NotAuthenticatedException
LockedOutException NotAuthenticatedException
LockoutRegionMismatchException NotAuthenticatedException
OneTimePasswordIncorrectException NotAuthenticatedException
TwoFactorAuthenticationErrorException NotAuthenticatedException
TwoFactorAuthenticationSetupExpiredException NotAuthenticatedException
ApiKeyIsDisabledException NotAuthorizedException
ApiKeyIsPathRestrictedException NotAuthorizedException
ApiKeyOnlyForDesktopAppException NotAuthorizedException
ApiKeyOnlyForFileOperationsException NotAuthorizedException
ApiKeyOnlyForMobileAppException NotAuthorizedException
ApiKeyOnlyForOfficeIntegrationException NotAuthorizedException
BillingInformationHiddenException NotAuthorizedException
BillingPermissionRequiredException NotAuthorizedException
BundleMaximumUsesReachedException NotAuthorizedException
BundlePermissionRequiredException NotAuthorizedException
CannotAdministerHigherLevelUserException NotAuthorizedException
CannotLoginWhileUsingKeyException NotAuthorizedException
CantActForOtherUserException NotAuthorizedException
ContactAdminForPasswordChangeHelpException NotAuthorizedException
FilesAgentFailedAuthorizationException NotAuthorizedException
FolderAdminOrBillingPermissionRequiredException NotAuthorizedException
FolderAdminPermissionRequiredException NotAuthorizedException
ForbiddenException NotAuthorizedException
FullPermissionRequiredException NotAuthorizedException
HistoryPermissionRequiredException NotAuthorizedException
InAppAiAssistantUnavailableException NotAuthorizedException
InsufficientPermissionForParamsException NotAuthorizedException
InsufficientPermissionForSiteException NotAuthorizedException
MoverAccessDeniedException NotAuthorizedException
MoverPackageRequiredException NotAuthorizedException
MustAuthenticateWithApiKeyException NotAuthorizedException
NeedAdminPermissionForInboxException NotAuthorizedException
NonAdminsMustQueryByFolderOrPathException NotAuthorizedException
NotAllowedToCreateBundleException NotAuthorizedException
NotEnqueuableSyncException NotAuthorizedException
PasswordChangeNotRequiredException NotAuthorizedException
PasswordChangeRequiredException NotAuthorizedException
PaymentMethodErrorException NotAuthorizedException
PreviewOnlyPermissionCannotDownloadException NotAuthorizedException
ReadOnlySessionException NotAuthorizedException
ReadPermissionRequiredException NotAuthorizedException
ReauthenticationFailedException NotAuthorizedException
ReauthenticationFailedFinalException NotAuthorizedException
ReauthenticationNeededActionException NotAuthorizedException
RecaptchaFailedException NotAuthorizedException
RemoteDesktopDebugLoggingDisabledException NotAuthorizedException
RootFolderBehaviorSiteAdminRequiredException NotAuthorizedException
RootFolderBehaviorSkipSiteAdminRequiredException NotAuthorizedException
SelfManagedRequiredException NotAuthorizedException
SiteAdminOrPartnerAdminPermissionRequiredException NotAuthorizedException
SiteAdminOrWorkspaceAdminOrFolderAdminPermissionRequiredException NotAuthorizedException
SiteAdminOrWorkspaceAdminOrPartnerAdminOrFolderAdminPermissionRequiredException NotAuthorizedException
SiteAdminOrWorkspaceAdminOrPartnerAdminPermissionRequiredException NotAuthorizedException
SiteAdminOrWorkspaceAdminPermissionRequiredException NotAuthorizedException
SiteAdminRequiredException NotAuthorizedException
SiteFilesAreImmutableException NotAuthorizedException
TwoFactorAuthenticationRequiredException NotAuthorizedException
UserIdWithoutSiteAdminException NotAuthorizedException
WriteAndBundlePermissionRequiredException NotAuthorizedException
WritePermissionRequiredException NotAuthorizedException
ApiKeyNotFoundException NotFoundException
BundlePathNotFoundException NotFoundException
BundleRegistrationNotFoundException NotFoundException
CodeNotFoundException NotFoundException
FileNotFoundException NotFoundException
FileUploadNotFoundException NotFoundException
GroupNotFoundException NotFoundException
InboxNotFoundException NotFoundException
NestedNotFoundException NotFoundException
PlanNotFoundException NotFoundException
SiteNotFoundException NotFoundException
UserNotFoundException NotFoundException
AgentPushUpdateBlockedException ProcessingFailureException
AgentUnavailableException ProcessingFailureException
AiTaskCannotBeRunManuallyException ProcessingFailureException
AlreadyCompletedException ProcessingFailureException
AutomationCannotBeRunManuallyException ProcessingFailureException
BehaviorNotAllowedOnRemoteServerException ProcessingFailureException
BufferedUploadDisabledForThisDestinationException ProcessingFailureException
BundleOnlyAllowsPreviewsException ProcessingFailureException
BundleOperationRequiresSubfolderException ProcessingFailureException
ConfigurationLockedPathException ProcessingFailureException
CouldNotCreateParentException ProcessingFailureException
DestinationExistsException ProcessingFailureException
DestinationFolderLimitedException ProcessingFailureException
DestinationParentConflictException ProcessingFailureException
DestinationParentDoesNotExistException ProcessingFailureException
ExceededRuntimeLimitException ProcessingFailureException
ExpectationAlreadyHasOpenWindowException ProcessingFailureException
ExpectationNotManualTriggerException ProcessingFailureException
ExpiredPrivateKeyException ProcessingFailureException
ExpiredPublicKeyException ProcessingFailureException
ExportFailureException ProcessingFailureException
ExportNotReadyException ProcessingFailureException
FailedToChangePasswordException ProcessingFailureException
FileLockedException ProcessingFailureException
FileNotUploadedException ProcessingFailureException
FilePendingProcessingException ProcessingFailureException
FileProcessingErrorException ProcessingFailureException
FileTooBigToDecryptException ProcessingFailureException
FileTooBigToEncryptException ProcessingFailureException
FileUploadedToWrongRegionException ProcessingFailureException
FilenameTooLongException ProcessingFailureException
FolderLockedException ProcessingFailureException
FolderNotEmptyException ProcessingFailureException
HistoryUnavailableException ProcessingFailureException
InvalidBundleCodeException ProcessingFailureException
InvalidFileTypeException ProcessingFailureException
InvalidFilenameException ProcessingFailureException
InvalidPriorityColorException ProcessingFailureException
InvalidRangeException ProcessingFailureException
InvalidSiteException ProcessingFailureException
InvalidZipFileException ProcessingFailureException
MetadataNotSupportedOnRemotesException ProcessingFailureException
ModelSaveErrorException ProcessingFailureException
MultipleProcessingErrorsException ProcessingFailureException
PathTooLongException ProcessingFailureException
RecipientAlreadySharedException ProcessingFailureException
RemoteEntryReadOnlyException ProcessingFailureException
RemoteServerErrorException ProcessingFailureException
ResourceBelongsToParentSiteException ProcessingFailureException
ResourceLockedException ProcessingFailureException
SearchTimedOutException ProcessingFailureException
SubfolderLockedException ProcessingFailureException
SyncInProgressException ProcessingFailureException
TwoFactorAuthenticationCodeAlreadySentException ProcessingFailureException
TwoFactorAuthenticationCountryBlacklistedException ProcessingFailureException
TwoFactorAuthenticationGeneralErrorException ProcessingFailureException
TwoFactorAuthenticationMethodUnsupportedErrorException ProcessingFailureException
TwoFactorAuthenticationUnsubscribedRecipientException ProcessingFailureException
UpdatesNotAllowedForRemotesException ProcessingFailureException
DuplicateShareRecipientException RateLimitedException
FilesNativeStorageOverloadedException RateLimitedException
ReauthenticationRateLimitedException RateLimitedException
TooManyConcurrentLoginsException RateLimitedException
TooManyConcurrentRequestsException RateLimitedException
TooManyLoginAttemptsException RateLimitedException
TooManyRequestsException RateLimitedException
TooManySharesException RateLimitedException
AutomationsUnavailableException ServiceUnavailableException
LockOperationBusyException ServiceUnavailableException
MigrationInProgressException ServiceUnavailableException
SearchUnavailableException ServiceUnavailableException
SiteDisabledException ServiceUnavailableException
UploadsUnavailableException ServiceUnavailableException
AccountAlreadyExistsException SiteConfigurationException
AccountOverdueException SiteConfigurationException
NoAccountForSiteException SiteConfigurationException
SiteWasRemovedException SiteConfigurationException
TrialExpiredException SiteConfigurationException
TrialLockedException SiteConfigurationException
UserRequestsEnabledRequiredException SiteConfigurationException

Pagination

Some API operations divide large lists of results into pages. The PHP SDK supports both iterating through those results and requesting individual pages.

Each list method that pages through its results with a cursor has a page counterpart that fetches one page at a time: Folder::listFor() has Folder::listForPage(), User::all() has User::listPage(), and so on. A page method takes the same parameters and options as its list method and returns a \Files\Page.

Automatic Pagination

autoPagingIterator() yields every item from a page onward. It requests each following page only when the loop reaches it, so a break sends no further requests. Pages can be empty and still be followed by more items; the iterator keeps going until the API reports the last page.

try {
  $files = \Files\Model\Folder::listForPage($path, ['per_page' => 1000])->autoPagingIterator();
  foreach ($files as $file) {
    // Operate on $file
  }
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Manual Pagination

A foreach over a page visits only the items on that page. nextPage() fetches the next page and returns null, without a request, once hasNextPage() is false. A page never changes after it is fetched, so if fetching the next page fails, the current page is still usable and nextPage() can be called again. If the API returns a cursor that already led to that page or an earlier one, nextPage() raises \Files\Exception\ApiBadResponseException instead of repeating pages.

Every page is requested with the parameters and options given to the page method, without an added page number. Settings those options do not override, such as the API key set with \Files\Files::setApiKey(), are read as each page is requested.

try {
  $page = \Files\Model\Folder::listForPage($path, ['per_page' => 1000]);
  while ($page !== null) {
    foreach ($page as $file) {
      // Operate on $file
    }
    $page = $page->nextPage();
  }
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Resuming and Restarting

getNextCursor() returns the opaque cursor for the next page, or null on the last page, where there is nothing to continue. Pass a cursor back unchanged, as the cursor parameter of the same page method, to continue from there later, for example in another process.

restart() fetches the first page again with the original parameters and options, without any cursor.

try {
  $page = \Files\Model\Folder::listForPage($path, ['per_page' => 1000]);
  $cursor = $page->getNextCursor();

  // Later: continue with the page after $page, if there is one
  if ($cursor !== null) {
    $next = \Files\Model\Folder::listForPage($path, ['per_page' => 1000, 'cursor' => $cursor]);
  }

  // At any time: start over from the first page
  $first = $page->restart();
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Lists as Arrays

The list methods themselves return an array. With \Files\Files::$autoPaginate set to true, the default, they fetch every page before returning, holding the entire list in memory. With false, they return only the first page. Page methods are not affected by this setting.

A list method stops with \Files\Exception\ApiBadResponseException when a page is not a list, or when the API returns a cursor the list already sent, instead of requesting pages without end.

// true by default
\Files\Files::$autoPaginate = true;

try {
  $files = \Files\Model\Folder::listFor($path, [
    'search' => "some-partial-filename"
  ]);
  foreach ($files as $file) {
    // Operate on $file
  }
} catch (\Files\Exception\NotAuthenticatedException $e) {
  echo 'Authentication Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
} catch (\Files\Exception\FilesException $e) {
  echo 'Unknown Error Occurred (' . get_class($e) . '): ', $e->getMessage(), "\n";
}

Waiting for File Actions

File operations such as copy and move can finish in the background. Their default methods return a FileAction as soon as the API accepts the operation. Call waitForCompletion() on that action when subsequent work depends on it finishing.

$file = new \Files\Model\File(['path' => 'reports/source.csv']);
$action = $file->copy(['destination' => 'reports/destination.csv']);
$migration = $action->waitForCompletion(['timeout' => 60]);

The wait checks the action's File Migration immediately, then waits one second between polls while it is pending or processing. It returns the completed FileMigration. An action already marked completed without a migration returns null. An action without an observable completion status raises \Files\Exception\FileActionException.

Set interval to change the delay between polls, in seconds. Set timeout to limit the polling loop, also in seconds. Omitting it waits without a polling deadline. The timeout is checked before and after each poll, and limits the delay between polls. An in-flight API request retains its configured HTTP timeouts and retries, so it can finish after the polling timeout.

A progress callback receives each FileMigration. Throwing from the callback stops the wait and propagates the same exception. Stopping or timing out the wait leaves the operation running on Files.com.

$migration = $action->waitForCompletion([
    'interval' => 0.5,
    'timeout' => 60,
    'progress' => function ($migration) {
        echo $migration->getFilesMoved() . " files processed\n";
    },
]);

A failed or cancelled migration raises \Files\Exception\FileActionException with its status and any available failure message. The exception's getFileAction() and getFileMigration() methods return the action and the latest observed migration. API request failures propagate as their existing SDK exceptions. Each poll uses the action's request options.

Mock Server

Files.com publishes a mock Files.com API server, which is useful for testing your use of the Files.com SDKs and other direct integrations against the Files.com API in an integration test environment. It never checks credentials: send any placeholder API key, such as YOUR_API_KEY, and never use real Files.com credentials with it.

The server has two modes, chosen when it starts:

  • Legacy mode (the default) checks required parameters and parameter types, then returns a fixed example response for each API endpoint. It does not maintain state and it does not deeply inspect your submissions for correctness, which makes it useful for testing basic network operations and JSON encoding for your SDK or API client.
  • Simulation mode keeps records, files and folders in memory, so a test can create, list, update and delete resources, upload a file and download the same bytes, and make chosen requests fail, stall or lose their connection on purpose. Requests it does not simulate fail with a clear error instead of returning an example response.

Quick Start with Docker

With Docker installed, start the published image from Docker Hub with the command shown. It runs legacy mode at http://127.0.0.1:4041, reachable from your machine only: point your integration's Files.com API base URL there and use a placeholder API key. Stop it with Ctrl+C; --rm removes its container.

The published image is built for linux/amd64 only, so the command asks for that platform; without it, Docker on a machine of another architecture, such as an Apple silicon Mac, looks for an image the tag does not have. The latest tag moves to whichever server was published last, and --pull=always fetches it again each time, so it need not include simulation mode. To run simulation mode, build the image from the source as below.

docker run --platform linux/amd64 --rm --pull=always -p 127.0.0.1:4041:4041 filescom/files-mock-server:latest

## In another terminal, with a placeholder API key:
curl -H "X-FilesAPI-Key: YOUR_API_KEY" http://127.0.0.1:4041/api/rest/v1/users

Simulation Mode in Docker

To run exactly the server the source's README describes, simulation mode included, build the image from a checkout of the source on GitHub and run it by the image ID you record with your test results. Only linux/amd64 builds of the source have been checked, so both commands ask for that platform.

Simulation mode listens only on loopback unless told otherwise, so the command binds it to the container's interfaces with -b tcp://0.0.0.0:4041 and publishes the port on your machine's loopback address only. FILES_MOCK_TRANSFER_ORIGIN tells it the address your tests use, so the upload and download URLs it returns point at the published port.

Simulation mode keeps its state only in the server process. Its control endpoints under /__files_mock/v1 report when the server is ready, reset it with your fixtures, add fault rules and return the journal of the requests it received. It refuses work over its limits instead of truncating it. The README in the source describes all of these, the operations it simulates and how to configure its limits.

## In a checkout of the source:
docker build --platform linux/amd64 -t files-mock-server:local .
image=$(docker image inspect --format '{{.Id}}' files-mock-server:local)
echo "$image"   # record this ID with your test results
docker run --platform linux/amd64 --rm -e FILES_MOCK_MODE=simulation \
  -e FILES_MOCK_TRANSFER_ORIGIN=http://127.0.0.1:40410 \
  -p 127.0.0.1:40410:4041 "$image" -b tcp://0.0.0.0:4041

## In another terminal:
curl http://127.0.0.1:40410/__files_mock/v1/ready

From the Source with Ruby

Start the server from its source with Ruby and Bundler. FILES_MOCK_MODE is read once at startup: leaving it unset or setting it to legacy starts legacy mode, simulation starts simulation mode, and any other value stops startup with an error. Legacy mode listens on port 4041 on all IPv4 interfaces, and simulation mode on 127.0.0.1:4041.

bundle install

## Legacy mode
bundle exec puma

## Simulation mode
FILES_MOCK_MODE=simulation bundle exec puma

Upgrading

Errors, Models and Lists

Every 5xx response still raises ApiServerException, whatever its body, and transport failures raise the same exception classes as before. These responses and calls behave differently now:

Response or call Earlier releases Now
A 4xx response without a Files.com error object, such as null, [], HTML or malformed JSON FilesException or ApiException ApiBadResponseException
A 4xx error object whose type is unknown, malformed, not a string, or names an SDK exception A PHP Error or TypeError, or FilesException ApiException
A 4xx response written to a stream that cannot be read A RuntimeException ApiBadResponseException
An ApiException getter for a field the error object does not include A PHP notice or warning, and null null

ApiBadResponseException, ApiServerException and the other Api* exceptions now extend the new ApiConnectionException, which extends FilesException, so code that catches them needs no change.

The message of an exception for an HTTP error response now names the request, as in The GET request failed with HTTP 404 Not Found (not-found)., instead of repeating the HTTP client's message with the start of the response body. Read the API's own error message with getError().

A method that returns a model, such as create(), find() or update(), now raises ApiBadResponseException when the response is not a JSON object, where earlier releases returned an empty model. save() then leaves the object as it was, instead of replacing its attributes and returning true. A list response that is not a JSON array, or an entry of a list of models that is not a JSON object, raises it too.

update() now also refreshes the object it is called on with the saved attributes, and still returns them as a separate model.

A method without parameters, such as ApiKey::findCurrent(), now uses its options, such as api_key and workspace_id, for its request, where earlier releases sent them as request parameters.

An auto-paginated list method now reads the next page's cursor from X-Files-Cursor-Next whenever the response has that header, and from X-Files-Cursor otherwise, and follows a cursor of 0. A list that returns a cursor it already sent raises ApiBadResponseException instead of requesting pages without end. List methods that page with a cursor also have page counterparts, such as Folder::listForPage(); see Pagination.

Credentials and Parameters

An api_key option, given to a model object or a method, now takes the place of a session set with Files::setSessionId() as well as the API key set with Files::setApiKey(); earlier releases sent that session instead. A session_id option is still used before an api_key option, and without either the configured session is still used before the configured API key. An option that PHP reads as false, such as null, '' or '0', is ignored, as before.

Creating a session still sends no API key of the SDK's own; given an api_key option, it no longer sends the configured session either.

A TransferJob's api_key, session_id and workspace_id options still replace the job's copy of those settings whenever they are given, null and false included. A job's api_key that PHP reads as true now also takes the place of the session the job copied from Files::setSessionId(), unless the job is given such a session_id as well. A transfer's own options choose as a request's options do.

A model method now raises InvalidParameterException, before it sends anything, for an integer, string or array parameter given false, or another empty value of the wrong type such as '' for an integer, where earlier releases sent it. A required parameter other than a boolean that is missing or empty still raises MissingParameterException. A required boolean parameter now accepts false, including from the model object's own attribute, and a boolean parameter raises InvalidParameterException for an array or object.

Exception Namespaces

Version 2.0 adopted the PSR-12 coding standard and PSR-4 autoloading standard. That change did not add or remove classes, though some classes moved to new namespaces and source files. If your application references those classes, you need to update its imports or fully qualified class names.

The main namespace changes were to exception classes. Base exceptions moved from \Files to \Files\Exception, and the error groups moved into corresponding subnamespaces, such as \Files\NotFound becoming \Files\Exception\NotFound.

These examples show the namespace changes:

Before 2.0 2.0 and Later
\Files\ApiException Files\Exception\ApiException
\Files\FilesException Files\Exception\FilesException
\Files\ConfigurationException Files\Exception\ConfigurationException
\Files\BadRequest\AgentUpgradeRequiredException Files\Exception\BadRequest\AgentUpgradeRequiredException
\Files\NotAuthenticated\AdditionalAuthenticationRequiredException Files\Exception\NotAuthenticated\AdditionalAuthenticationRequiredException
\Files\NotAuthorized\ApiKeyIsDisabledException Files\Exception\NotAuthorized\ApiKeyIsDisabledException
\Files\NotFound\ApiKeyNotFoundException Files\Exception\NotFound\ApiKeyNotFoundException
\Files\ProcessingFailure\AlreadyCompletedException Files\Exception\ProcessingFailure\AlreadyCompletedException
\Files\RateLimited\DuplicateShareRecipientException Files\Exception\RateLimited\DuplicateShareRecipientException
\Files\ServiceUnavailable\AgentUnavailableException Files\Exception\ServiceUnavailable\AgentUnavailableException
\Files\SiteConfiguration\AccountAlreadyExistsException Files\Exception\SiteConfiguration\AccountAlreadyExistsException

Upload Completion

The upload helpers, including File::uploadFile, File::uploadData, the uploadTo... helpers, adaptive transfers and files:// write streams, return only after Files.com has completed the upload.

For a remote server mount or Files.com Agent, finalization can continue in the background after the last part arrives. The helper checks the outcome every second until Files.com reports completion or failure.

Each status response produces another progress report with the last part's byte counts, part_bytes set to 0 and finalizing set to true. The finalization_progress field contains the percentage reported by Files.com, or null if the response supplied none. Byte counts do not change while the helper waits, and even a percentage of 100 does not confirm completion. Wait for the helper's result before treating the upload as complete.

Cancelling a transfer job or throwing from its callback stops the SDK's wait, though Files.com may still complete the upload. The same uncertainty applies if the SDK cannot use a status response or its requests keep failing; the resulting error identifies that the outcome is unknown. An error returned by Files.com itself, such as a finalization failure, is the upload's reported outcome.

Adaptive Transfers (64-bit PHP)

The upload and download helpers send one request at a time unless they are given the transfer option. With it, they run adaptively: upload parts and download ranges go concurrently, as many as measured throughput and response times justify, within the limits you set.

Adaptive transfers need 64-bit PHP integers (PHP_INT_SIZE 8) and a native monotonic clock: PHP 7.3 or later (its hrtime), or, on older 64-bit PHP, the hrtime extension (PECL hrtime 0.6.0 or later, HRTime\PerformanceCounter). You can check whether the runtime supports adaptive transfers with \Files\Transfer\TransferJob::isSupported(). On an unsupported runtime, using the transfer option throws ConfigurationException before anything is read, sent or written. The ordinary helpers without that option remain available. Linux and macOS clocks stop while the computer sleeps; Windows' keeps counting.

// One upload or download, adaptively:
\Files\Model\File::uploadFile('reports/a.csv', '/tmp/a.csv', [], ['transfer' => ['startup' => 'default']]);
\Files\Model\File::uploadData('reports/b.csv', $stream, [], ['transfer' => ['size' => $bytes]]);
$result = \Files\Model\File::downloadToFile('reports/a.csv', '/tmp/copy.csv', true, ['transfer' => []]);

// Several transfers sharing one set of limits and what they learn:
$job = new \Files\Transfer\TransferJob(['max_concurrent_requests' => 32]);
$job->uploadFile('reports/c.csv', '/tmp/c.csv', [], ['progress' => function ($report) {
    echo $report['acknowledged_bytes'] . ' bytes at ' . round($report['bytes_per_second']) . " bytes/s\n";
}]);
$job->downloadToStream('reports/d.csv', $writableStream);
$job->wait();

Options of a TransferJob (and of the transfer option):

  • startup: default starts an upload to Amazon S3 with one part in flight and adds more only as measurements justify; aggressive starts at the policy's start, for a link known to be fast. Both remain adaptive and share the same eventual limits. Uploads only: downloads start at the policy's start.
  • concurrency: a fixed number of content requests in flight. initial_target: an explicit starting target.
  • max_concurrent_requests (default 64, at most 1024): every request in flight counts, API requests included.
  • max_concurrent_files (default 128) and max_buffer_bytes (default 64 MiB, or half the memory PHP reports free under its memory_limit when that is less): a hard limit on the bytes held for parts and ranges.
  • max_retries (default Files::$maxNetworkRetries; it also bounds the restarts of a download whose file changed), download_part_bytes (default 8 MiB), diagnostics (a callable given each concurrency decision), and api_key, session_id and workspace_id.

A job copies the SDK's configuration when it is made; later changes do not reach it. Its requests are pooled in its own curl multi handle, or in the GuzzleHttp\Handler\CurlMultiHandler you set with Files::setHandler. Any other handler set there is used one request at a time (statistics()['transport'] is then serial), and a job given concurrency, initial_target or Aggressive startup with such a handler is refused.

Upload Parts

The SDK acknowledges an upload part only when storage returns exactly one ETag for it. A failed part is retried with the same bytes unless its grant sets retry_parts to false, and an acknowledged part is never sent again. The helper waits for every part and progress callback to finish and for Files.com to complete finalization before returning; see Upload Completion.

For an ordinary multipart upload directly to Amazon S3, the SDK chooses 8 MiB parts, increasing the size if the file would need more than 10,000 parts. Elsewhere, the API supplies the sizes. A stream with no known size is sent one part at a time.

Download Versions and Destinations

For storage that supports version-bound ranges, the SDK sends the file's strong ETag in If-Match so that every range belongs to the same version. A response containing fewer bytes, more bytes or a different range is rejected and retried within max_retries. If those retries are exhausted, the download fails.

A detected source change requires the download to start again from its first byte. The SDK treats a different or weak ETag, a changed total size, HTTP 412, a newer Last-Modified, or a storage HTTP 409 response with a complete JSON body of at most 4 KiB and type download_source_changed as evidence of a source change.

Before restarting, the SDK cancels all requests in flight, including URL renewal, and waits for them to settle. It then obtains a fresh download URL and discards the previous version's bytes and metadata so that versions cannot mix. Each restart counts against the whole download's max_retries, regardless of how far it progressed. A source change with max_retries set to 0 fails immediately. A stream that has already received bytes also fails instead of restarting, because it cannot take back the bytes already delivered.

Other HTTP 409 responses and other permanent failures end the download immediately. Responses from the Files.com web app (X-Files-Frontend-App) fail before writing any bytes. Storage without version-bound ranges is downloaded in one response, restarting from byte zero after interruption.

A local download is written to a staging file beside the destination. The SDK replaces the destination only after every byte has been verified, so a failed attempt leaves the previous destination unchanged. A stream receives bytes in order and never receives the same byte twice.

Expired Transfer URLs

The SDK renews a signed URL before sending it if it expires within 15 seconds. It also renews after storage returns HTTP 403 for a URL past its expiration, or HTTP 400 or 403 with a recognized expiry response regardless of its stated expiration.

Recognized responses include S3's Request has expired, Amazon or Google's <Code>ExpiredToken</Code>, and Azure's Signature not valid in the specified time frame, matched without regard to case in the first 4 KiB. A complete Files.com JSON error of at most 4 KiB also qualifies when its type is download_request_expired or upload_request_expired. A body beginning with {, [ or " is evaluated only as JSON by that type, never by text inside it.

Resending after an expiry refusal counts as a retry, with at most three renewals per part or range. An upload part is renewed only when its grant permits retries. Other HTTP 403 responses fail the transfer without renewal.

wait() throws the first failure, or the first exception a callback throws, as it was, after stopping everything in flight; cancel() makes it throw a TransferCancelledException. pause(), from a callback or between waits, stops the job keeping everything accepted, and resume() then wait() continue it without sending accepted bytes again. A paused job lives in its process: keep the job, its files and streams open and unchanged until it resumes. Nothing is saved for another process or after a crash.

These defaults are starting choices of this SDK, not measured performance.

Expired Transfer URLs Without Adaptive Transfers

Ordinary transfers use the same recognized expiry responses as adaptive transfers. This applies to uploadFile, uploadData, the uploadTo... helpers, downloadToStream, partialDownloadToFile, resumeDownloadToFile, downloadToFile and files:// handles, across supported PHP and Guzzle versions and handlers configured with Files::setHandler.

The SDK renews a URL using the file's path and the request context captured when the call or handle began. An upload then resends the same part number and bytes under the same ref, while a download requests the same range. Each part, download or range can be renewed at most three times. Those renewals count against Files::$maxNetworkRetries along with connection retries and the retries performed by downloadToFile.

The SDK does not renew a URL when no retry remains, when downloadToFile has $enableRetry set to false, or when an upload part's grant sets retry_parts to false. If a renewed grant changes the part's ref, number, size, method, headers, parameters or send instructions, or withdraws retry permission, the upload fails before the part is sent again. A replacement URL that has already expired according to its query is not sent.

A files:// read handle also verifies that the file still has the size recorded when the handle was opened and, once known, the same version.

Bytes from a response identified as expired never reach the download destination, whether or not renewal succeeds. Other refusal bodies retain their ordinary behavior. The SDK holds at most 4 KiB plus one byte of a refusal in memory. Bytes a handler writes before reporting the status to on_headers are held in a temporary stream, which spills to disk above 1 MiB.

A Files.com JSON expiry error qualifies only if the entire body arrives, including every byte declared by Content-Length. Recognized storage text can qualify from the portion received.

After three renewals, downloadToFile fails that expiry refusal rather than retrying it as another failure. It resumes only from bytes written by the current call. Until a response body reaches the destination, a retry starts at byte zero, regardless of the file's previous contents.

A caller-supplied destination stream stays open for you to close, with any handler. Api::sendFile and getDownloadUrl return URLs alone; they have no file path from which to renew them.

Native File and Directory Handles

Use PHP file and SPL interfaces through the files:// stream wrapper. See native files and native directories for registration, supported operations and limitations.

API Region Routing

See API region routing for automatic region continuation and its policy override.

Native PHP API Reference

The generated classes include PHPDoc for model properties, accessors and API operations, including request parameters and return types. IDEs can read these comments directly. The generated Markdown reference remains in docs/Model/.

To build a browsable phpDocumentor reference, install the separate documentation tools using PHP 8.1.2 or later, then run the documentation build from this SDK's root:

composer --working-dir=tools/phpdoc install
composer docs

Open docs/api/index.html to browse the result. The documentation tool's requirements do not change the PHP versions or Guzzle versions supported by the SDK. The builder analyzes source files without loading the SDK or making API requests.

./build.sh --docs runs the same build without Composer's script wrapper. To use an existing phpDocumentor 3 executable or PHAR, set PHPDOC_BIN to its path. Set PHPDOC_PHP to the PHP executable used by the builder when it differs from php. A plain ./build.sh checks PHP source syntax and reports how to build the reference. To generate and build the reference in one SDK Generator command, set PHPDOC_BIN to an absolute tool path outside generated/php and run bundle exec ruby files-sdk-generator.rb --target php --build-args=--docs. Regeneration replaces the generated SDK, including locally installed tools.

Modification Dates During Downloads

Files::$checkDownloadModificationTime defaults to true. A transfer job snapshots the global setting and can override it; a download's local option wins over the job default:

Files::$checkDownloadModificationTime = false;
$job = new \Files\Transfer\TransferJob(['check_download_modification_time' => false]);
$job->downloadToFile('remote.bin', 'local.bin', ['check_download_modification_time' => true]);
$job->wait();

For ordinary downloads, use File::downloadToFile($remote, $local, true, ['check_download_modification_time' => false]). downloadToStream and partialDownloadToFile take the same options as their fifth argument, and resumeDownloadToFile as its third. Native files:// handles accept it in files.options of the stream context. Each download/read handle retains the effective boolean through retries and renewal.

Disabling this option suppresses automatic date preconditions and newer-date checks. Source changes detectable only by timestamps can then go undetected; strong ETag/version, size, byte and HTTP error checks remain enabled.

When storage supplies a valid Last-Modified HTTP date, the SDK retains that first date for the download. Subsequent requests, retries and signed URL renewals send it as If-Unmodified-Since unless stronger version protection applies. An HTTP 412 response, or a successful response with a newer valid date, stops the attempt before its body is used. A missing or invalid date does not by itself fail the download.

Because HTTP dates have one-second precision, this check cannot detect preserved timestamps, same-second edits or changes during a single response. It does not establish a strong version of the file, enable parallel downloads or provide the validation needed for persistent resume.

A file with a future modification time can be refused even if it has not changed. If that happens, correct the source machine's clock and the file's modification time before retrying.

An adaptive download restarts from its first byte when the source changes, within the job's max_retries; see Adaptive Transfers. The destination file remains unchanged until a complete download of one version replaces it. If the source continues changing until that retry budget is exhausted, the download fails.

The ordinary downloadToFile helper retains the same date while continuing an interrupted response. If it detects a source change, it fails and can leave a partial destination file. Once the source is stable, retry the complete download. Stream downloads do not replay bytes that have already been delivered.

A files:// read handle retains its date baseline across ranges and URL renewals. A separately invoked resumeDownloadToFile has no date from the earlier call, so it cannot use modification time to validate bytes retained from that call. Returning only a download URL does not send a content request.