files.com / files-php-sdk
Files.com PHP SDK
Installs: 43 223
Dependents: 0
Suggesters: 0
Security: 0
Stars: 22
Watchers: 9
Forks: 6
Open Issues: 1
Requires
- php: >=5.5.0
- ext-curl: *
- ext-intl: *
- ext-json: *
- ext-mbstring: *
- guzzlehttp/guzzle: ^6 || ^7
- dev-master
- v2.0.32
- v2.0.31
- v2.0.30
- v2.0.29
- v2.0.28
- v2.0.27
- v2.0.26
- v2.0.25
- v2.0.24
- v2.0.23
- v2.0.22
- v2.0.21
- v2.0.20
- v2.0.19
- v2.0.18
- v2.0.17
- v2.0.16
- v2.0.15
- v2.0.14
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.2.71
- v1.2.70
- v1.2.69
- v1.2.68
- v1.2.67
- v1.2.66
- v1.2.65
- v1.2.64
- v1.2.63
- v1.2.62
- v1.2.61
- v1.2.60
- v1.2.59
- v1.2.58
- v1.2.57
- v1.2.56
- v1.2.55
- v1.2.54
- v1.2.53
- v1.2.52
- v1.2.51
- v1.2.50
- v1.2.49
- v1.2.48
- v1.2.47
- v1.2.46
- v1.2.45
- v1.2.44
- v1.2.43
- v1.2.42
- v1.2.41
- v1.2.40
- v1.2.39
- v1.2.38
- v1.2.37
- v1.2.36
- v1.2.35
- v1.2.34
- v1.2.33
- v1.2.32
- v1.2.31
- v1.2.30
- v1.2.29
- v1.2.28
- v1.2.27
- v1.2.26
- v1.2.25
- v1.2.24
- v1.2.23
- v1.2.22
- v1.2.21
- v1.2.20
- v1.2.19
- v1.2.18
- v1.2.17
- v1.2.16
- v1.2.15
- v1.2.14
- v1.2.13
- v1.2.12
- v1.2.11
- v1.2.10
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.475
- v1.0.474
- v1.0.473
- v1.0.472
- v1.0.471
- v1.0.470
- v1.0.469
- v1.0.468
- v1.0.467
- v1.0.466
- v1.0.465
- v1.0.464
- v1.0.463
- v1.0.462
- v1.0.461
- v1.0.460
- v1.0.459
- v1.0.458
- v1.0.457
- v1.0.456
- v1.0.455
- v1.0.454
- v1.0.453
- v1.0.452
- v1.0.451
- v1.0.450
- v1.0.449
- v1.0.448
- v1.0.447
- v1.0.446
- v1.0.445
- v1.0.444
- v1.0.443
- v1.0.442
- v1.0.441
- v1.0.440
- v1.0.439
- v1.0.438
- v1.0.437
- v1.0.436
- v1.0.435
- v1.0.434
- v1.0.433
- v1.0.432
- v1.0.431
- v1.0.430
- v1.0.429
- v1.0.428
- v1.0.427
- v1.0.426
- v1.0.425
- v1.0.424
- v1.0.423
- v1.0.422
- v1.0.421
- v1.0.420
- v1.0.419
- v1.0.418
- v1.0.417
- v1.0.416
- v1.0.415
- v1.0.414
- v1.0.413
- v1.0.412
- v1.0.411
- v1.0.410
- v1.0.409
- v1.0.408
- v1.0.407
- v1.0.406
- v1.0.405
- v1.0.404
- v1.0.403
- v1.0.402
- v1.0.401
- v1.0.400
- v1.0.399
- v1.0.398
- v1.0.397
- v1.0.396
- v1.0.395
- v1.0.394
- v1.0.393
- v1.0.392
- v1.0.391
- v1.0.390
- v1.0.389
- v1.0.388
- v1.0.387
- v1.0.386
- v1.0.385
- v1.0.384
- v1.0.383
- v1.0.382
- v1.0.381
- v1.0.380
- v1.0.379
- v1.0.378
- v1.0.377
- v1.0.376
- v1.0.375
- v1.0.374
- v1.0.373
- v1.0.372
- v1.0.371
- v1.0.370
- v1.0.369
- v1.0.368
- v1.0.367
- v1.0.366
- v1.0.365
- v1.0.364
- v1.0.363
- v1.0.362
- v1.0.361
- v1.0.360
- v1.0.359
- v1.0.358
- v1.0.357
- v1.0.356
- v1.0.355
- v1.0.354
- v1.0.353
- v1.0.352
- v1.0.351
- v1.0.350
- v1.0.349
- v1.0.348
- v1.0.347
- v1.0.346
- v1.0.345
- v1.0.344
- v1.0.343
- v1.0.342
- v1.0.341
- v1.0.340
- v1.0.339
- v1.0.338
- v1.0.337
- v1.0.336
- v1.0.335
- v1.0.334
- v1.0.333
- v1.0.332
- v1.0.331
- v1.0.330
- v1.0.329
- v1.0.328
- v1.0.327
- v1.0.326
- v1.0.325
- v1.0.324
- v1.0.323
- v1.0.322
- v1.0.321
- v1.0.320
- v1.0.319
- v1.0.318
- v1.0.317
- v1.0.316
- v1.0.315
- v1.0.314
- v1.0.313
- v1.0.312
- v1.0.311
- v1.0.310
- v1.0.309
- v1.0.308
- v1.0.307
- v1.0.306
- v1.0.305
- v1.0.304
- v1.0.303
- v1.0.302
- v1.0.301
- v1.0.300
- v1.0.299
- v1.0.298
- v1.0.297
- v1.0.296
- v1.0.295
- v1.0.294
- v1.0.293
- v1.0.292
- v1.0.291
- v1.0.290
- v1.0.289
- v1.0.288
- v1.0.287
- v1.0.286
- v1.0.285
- v1.0.284
- v1.0.283
- v1.0.282
- v1.0.281
- v1.0.280
- v1.0.279
- v1.0.278
- v1.0.277
- v1.0.276
- v1.0.275
- v1.0.274
- v1.0.273
- v1.0.272
- v1.0.271
- v1.0.270
- v1.0.269
- v1.0.268
- v1.0.267
- v1.0.266
- v1.0.265
- v1.0.264
- v1.0.263
- v1.0.262
- v1.0.261
- v1.0.260
- v1.0.259
- v1.0.258
- v1.0.257
- v1.0.256
- v1.0.255
- v1.0.254
- v1.0.253
- v1.0.252
- v1.0.251
- v1.0.250
- v1.0.249
- v1.0.248
- v1.0.247
- v1.0.246
- v1.0.245
- v1.0.244
- v1.0.243
- v1.0.242
- v1.0.241
- v1.0.240
- v1.0.239
- v1.0.238
- v1.0.237
- v1.0.236
- v1.0.235
- v1.0.234
- v1.0.233
- v1.0.232
- v1.0.231
- v1.0.230
- v1.0.229
- v1.0.228
- v1.0.227
- v1.0.226
- v1.0.225
- v1.0.224
- v1.0.223
- v1.0.222
- v1.0.221
- v1.0.220
- v1.0.219
- v1.0.218
- v1.0.217
- v1.0.216
- v1.0.215
- v1.0.214
- v1.0.213
- v1.0.212
- v1.0.211
- v1.0.210
- v1.0.209
- v1.0.208
- v1.0.207
- v1.0.206
- v1.0.205
- v1.0.204
- v1.0.203
- v1.0.202
- v1.0.201
- v1.0.200
- v1.0.199
- v1.0.198
- v1.0.197
- v1.0.196
- v1.0.195
- v1.0.194
- v1.0.193
- v1.0.192
- v1.0.191
- v1.0.190
- v1.0.189
- v1.0.188
- v1.0.187
- v1.0.186
- v1.0.185
- v1.0.184
- v1.0.183
- v1.0.182
- v1.0.181
- v1.0.180
- v1.0.179
- v1.0.178
- v1.0.177
- v1.0.176
- v1.0.175
- v1.0.174
- v1.0.173
- v1.0.172
- v1.0.171
- v1.0.170
- v1.0.169
- v1.0.168
- v1.0.167
- v1.0.166
- v1.0.165
- v1.0.164
- v1.0.163
- v1.0.162
- v1.0.161
- v1.0.160
- v1.0.159
- v1.0.158
- v1.0.157
- v1.0.156
- v1.0.155
- v1.0.154
- v1.0.153
- v1.0.152
- v1.0.151
- v1.0.150
- v1.0.149
- v1.0.148
- v1.0.147
- v1.0.146
- v1.0.145
- v1.0.144
- v1.0.143
- v1.0.142
- v1.0.141
- v1.0.140
- v1.0.139
- v1.0.138
- v1.0.137
- v1.0.136
- v1.0.135
- v1.0.134
- v1.0.133
- v1.0.132
- v1.0.131
- v1.0.130
- v1.0.129
- v1.0.128
- v1.0.127
- v1.0.126
- v1.0.125
- v1.0.124
- v1.0.123
- v1.0.122
- v1.0.121
- v1.0.120
- v1.0.119
- v1.0.118
- v1.0.117
- v1.0.116
- v1.0.115
- v1.0.114
- v1.0.113
- v1.0.112
- v1.0.111
- v1.0.110
- v1.0.109
- v1.0.108
- v1.0.107
- v1.0.106
- v1.0.105
- v1.0.104
- v1.0.103
- v1.0.102
- v1.0.101
- v1.0.100
- v1.0.99
- v1.0.98
- v1.0.97
- v1.0.96
- v1.0.95
- v1.0.94
- v1.0.93
- v1.0.92
- v1.0.91
- v1.0.90
- v1.0.89
- v1.0.88
- v1.0.87
- v1.0.86
- v1.0.85
- v1.0.84
- v1.0.83
- v1.0.82
- v1.0.81
- v1.0.80
- v1.0.79
- v1.0.78
- v1.0.77
- v1.0.76
- v1.0.75
- v1.0.74
- v1.0.73
- v1.0.72
- v1.0.71
- v1.0.70
- v1.0.69
- v1.0.68
- v1.0.67
- v1.0.66
- v1.0.65
- v1.0.64
- v1.0.63
- v1.0.62
- v1.0.61
- v1.0.60
- v1.0.59
- v1.0.58
- v1.0.57
- v1.0.56
- v1.0.55
- v1.0.54
- v1.0.53
- v1.0.52
- v1.0.51
- v1.0.50
- v1.0.49
- v1.0.48
- v1.0.47
- v1.0.46
- v1.0.45
- v1.0.44
- v1.0.43
- v1.0.42
- v1.0.41
- v1.0.40
- v1.0.39
- v1.0.38
- v1.0.37
- v1.0.36
- v1.0.35
- v1.0.34
- v1.0.33
- v1.0.32
- v1.0.31
- v1.0.30
- v1.0.29
- v1.0.28
- v1.0.27
- v1.0.26
- v1.0.25
- v1.0.24
- v1.0.23
- v1.0.22
- v1.0.21
- v1.0.20
- v1.0.19
- v1.0.18
- v1.0.17
- v1.0.16
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
This package is auto-updated.
Last update: 2024-07-26 13:11:48 UTC
README
The Files.com PHP SDK provides convenient Files.com API access to applications written in PHP.
Installation
Install Composer. See https://packagist.org for more info.
If composer.phar
is already available, skip this step.
curl -sS https://getcomposer.org/installer | php
Install the SDK
php composer.phar require files.com/files-php-sdk
Requirements
- PHP 5.5+
- php-curl extension
Usage
Import and initialize
require 'vendor/autoload.php'; // set client to use a mock Files.com server for testing \Files\Files::setBaseUrl('https://MY-SUBDOMAIN.files.com');
Authentication
There are multiple ways to authenticate to the API.
Global API Key
You can set an API key globally like this:
\Files\Files::setApiKey('my-api-key');
Per-Request API Key
Or, you can pass an API key per-request, in the options array at the end of every method like this:
$user = new \Files\Model\User($params, array('api_key' => 'my-api-key'));
User Session
Or, you can open a user session by calling \Files\Model\Session::create()
$session = \Files\Model\Session::create(['username' => $username, 'password' => $password]);
Then use it globally for all subsequent API calls like this:
\Files\Files::setSessionId($session->id);
Or, you can pass the session ID per-request, in the options array at the end of every method like this:
$user = new \Files\Model\User($params, array('session_id' => $session->id));
Session example
$session = \Files\Model\Session::create(['username' => $myUsername, 'password' => $myPassword]); \Files\Files::setSessionId($session->id); // do something \Files\Model\ApiKey::all(['user_id' => 0]); // clean up when done \Files\Model\Session::destroy(); \Files\Files::setSessionId(null);
Setting Global Options
You can set the following global properties directly on the \Files\Files
class:
\Files\Files::$logLevel
- set to one of the following:\Files\LogLevel::NONE
\Files\LogLevel::ERROR
\Files\LogLevel::WARN
\Files\LogLevel::INFO
(default)\Files\LogLevel::DEBUG
\Files\Files::$debugRequest
- enable debug logging of API requests (default:false
)\Files\Files::$debugResponseHeaders
- enable debug logging of API response headers (default:false
)\Files\Files::$connectTimeout
- network connect timeout in seconds (default:30.0
)\Files\Files::$readTimeout
- network read timeout in seconds (default:90.0
)\Files\Files::$maxNetworkRetries
- max retries (default:3
)\Files\Files::$minNetworkRetryDelay
- minimum delay in seconds before retrying (default:0.5
)\Files\Files::$maxNetworkRetryDelay
- max delay in seconds before retrying (default:1.5
)\Files\Files::$autoPaginate
- auto-fetch all pages when results span multiple pages (default:true
)
Static File Operations
List files in root folder
$rootFiles = \Files\Model\Folder::listFor('/');
Uploading a file on disk
\Files\Model\File::uploadFile($destinationFileName, $sourceFilePath);
Uploading raw file data
\Files\Model\File::uploadData($destinationFileName, $fileData);
Download a file to stream
\Files\Model\File::downloadToStream($remoteFilePath, $outputStream);
Download a file to disk
// download entire file - with retries enabled \Files\Model\File::downloadToFile($remoteFilePath, $localFilePath); // partially download - just the first KB \Files\Model\File::partialDownloadToFile($remoteFilePath, $localFilePath, 0, 1023); // resume an incomplete download \Files\Model\File::resumeDownloadToFile($remoteFilePath, $localFilePath);
Getting a file record by path
$foundFile = \Files\Model\File::find($remoteFilePath);
File Object Operations
Getting a file record by path
$file = new \Files\Model\File(); $file->get($remoteFilePath);
Updating metadata
$file->update([ 'provided_mtime' => '2000-01-01T01:00:00Z', 'priority_color' => 'red', ]);
Retrieving metadata
$file->metadata([ 'with_previews' => true, 'with_priority_color' => true, ]);
Comparing Case insensitive files and paths
For related documentation see Case Sensitivity Documentation.
if(\Files\Util\PathUtil::same("Fïłèńämê.Txt", "filename.txt")) { echo "Paths are the same\n"; }
Additional Documentation
Additional docs are available at https://developers.files.com
Migrating to Version 2.0 from previous versions
In Version 2.0, the Files.com PHP SDK was updated to comply with both the PSR-12 coding standard and the PSR-4 autoloading standard. No new classes were added or any exising classes removed, but some where moved to comply with the PSR-4 standard. If a client of the sdk references the moved classes, the client code will need to be updated to reference the new location of these classes.
Exception Classes
The affected classes where primarly Exception classes. Exceptions where moved into their own namespace (and source files).
The following table shows the classes that where changed for compliance
Base Exceptions
The Base exception were moved from the \Files
namespace to the \Files\Exception
namespace.
Examples of Base Exceptions Classes moved.
BadRequest Exceptions
The BadRequest group of exceptions were moved from the \Files\BadRequest
namespace to the \Files\Exception\BadRequest
namespace.
Example of BadRequest Classes moved.
NotAuthenticated Exceptions
The NotAuthenticated group of exceptions were moved from the \Files\NotAuthenticated
namespace to the \Files\Exception\NotAuthenticated
namespace.
Example of NotAuthenticated Classes moved.
NotAuthorized Exceptions
The NotAuthorized group of exceptions were moved from the \Files\NotAuthorized
namespace to the \Files\Exception\NotAuthorized
namespace.
Example of NotAuthorized Classes moved.
NotFound Exceptions
The NotFound group of exceptions were moved from the \Files\NotFound
namespace to the \Files\Exception\NotFound
namespace.
Example of NotFound Classes moved.
ProcessingFailure Exceptions
The ProcessingFailure group of exceptions were moved from the \Files\ProcessingFailure
namespace to the \Files\Exception\ProcessingFailure
namespace.
Example of ProcessingFailure Classes moved.
RateLimited Exceptions
The ProcessingFailure group of exceptions were moved from the \Files\RateLimited
namespace to the \Files\Exception\RateLimited
namespace.
Example of RateLimited Classes moved.
ServiceUnavailable Exceptions
The ServiceUnavailable group of exceptions were moved from the \Files\ServiceUnavailable
namespace to the \Files\Exception\ServiceUnavailable
namespace.
Example of ServiceUnavailable Classes moved.
SiteConfiguration Exceptions
The SiteConfiguration group of exceptions were moved from the \Files\SiteConfiguration
namespace to the \Files\Exception\SiteConfiguration
namespace.
Example of SiteConfiguration Classes moved.
Getting Support
The Files.com team is happy to help with any SDK Integration challenges you may face.
Just email support@files.com and we'll get the process started.