├── .coveralls.yml ├── .empty ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .vscode └── php-sdk.code-workspace ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── composer.json ├── composer.lock ├── examples ├── 1-assembly-request.php ├── 2-assembly-form.php ├── 3-assembly-form-with-jquery-plugin.php ├── 4-fetch-assembly-status.php ├── 5-assembly-with-template.php ├── 6-assembly-with-timeout.php ├── 7-disable-ssl-verification.php ├── common │ └── loader.php └── fixture │ └── straw-apple.jpg ├── lib └── transloadit │ ├── CurlRequest.php │ ├── CurlResponse.php │ ├── Transloadit.php │ ├── TransloaditRequest.php │ └── TransloaditResponse.php ├── phpcs.xml ├── phpunit.xml ├── release.sh ├── test ├── bootstrap.php ├── config.php ├── fixture │ └── image-resize-robot.jpg ├── simple │ ├── CurlRequestTest.php │ ├── CurlResponseTest.php │ ├── TransloaditRequestTest.php │ ├── TransloaditResponseTest.php │ └── TransloaditTest.php └── system │ ├── CurlRequest │ └── CurlRequestRootTest.php │ ├── Transloadit │ ├── TransloaditAssemblyCreateTest.php │ └── TransloaditCreateAssemblyWaitForCompletionTest.php │ └── TransloaditRequest │ ├── Base.php │ ├── TransloaditRequestAssemblyCreateTest.php │ ├── TransloaditRequestErrorTest.php │ ├── TransloaditRequestGetBillTest.php │ ├── TransloaditRequestHttpsRootTest.php │ ├── TransloaditRequestNoJsonErrorTest.php │ └── TransloaditRequestRootTest.php └── tool ├── generate-example-docs.php └── node-smartcdn-sig.ts /.coveralls.yml: -------------------------------------------------------------------------------- 1 | # for php-coveralls 2 | # https://coveralls.io/r/transloadit/php-sdk 3 | # https://github.com/satooshi/php-coveralls 4 | src_dir: lib/transloadit 5 | coverage_clover: build/logs/clover.xml 6 | -------------------------------------------------------------------------------- /.empty: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/transloadit/php-sdk/4eabc08bfb2cd8744c35d13238587190379a0e4e/.empty -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | push: 4 | branches: 5 | - main 6 | pull_request: 7 | types: 8 | - opened 9 | - synchronize 10 | jobs: 11 | ci: 12 | runs-on: ubuntu-latest 13 | strategy: 14 | fail-fast: true 15 | max-parallel: 1 16 | matrix: 17 | php: 18 | - 8.1 19 | - 8.2 20 | dependencies: 21 | - locked 22 | - lowest 23 | - highest 24 | name: PHP ${{ matrix.php }} - ${{ matrix.dependencies }} 25 | steps: 26 | - uses: actions/checkout@v4 27 | with: 28 | fetch-depth: 1 29 | - uses: actions/setup-node@v4 30 | with: 31 | node-version: '20' 32 | - name: Install tsx 33 | run: npm install -g tsx 34 | - uses: shivammathur/setup-php@v2 35 | with: 36 | php-version: ${{ matrix.php }} 37 | tools: php-cs-fixer, phpunit 38 | coverage: ${{ matrix.php == '8.1' && matrix.dependencies == 'locked' && 'xdebug' || 'none' }} 39 | - uses: ramsey/composer-install@v3 40 | with: 41 | dependency-versions: ${{ matrix.dependencies }} 42 | composer-options: '--ignore-platform-reqs' 43 | - name: Test with Coverage 44 | if: matrix.php == '8.1' && matrix.dependencies == 'locked' 45 | run: | 46 | make test-all-coverage 47 | env: 48 | TRANSLOADIT_KEY: ${{secrets.TEST_ACCOUNT_KEY}} 49 | TRANSLOADIT_SECRET: ${{secrets.TEST_ACCOUNT_SECRET}} 50 | TEST_NODE_PARITY: 1 51 | - name: Test without Coverage 52 | if: matrix.php != '8.1' || matrix.dependencies != 'locked' 53 | run: | 54 | make test-all 55 | env: 56 | TRANSLOADIT_KEY: ${{secrets.TEST_ACCOUNT_KEY}} 57 | TRANSLOADIT_SECRET: ${{secrets.TEST_ACCOUNT_SECRET}} 58 | TEST_NODE_PARITY: 1 59 | - name: Publish Coverage Report 60 | if: github.event_name == 'pull_request' && matrix.php == '8.1' && matrix.dependencies == 'locked' 61 | uses: lucassabreu/comment-coverage-clover@v0.13.0 62 | with: 63 | file: ./build/logs/clover.xml 64 | with-table: true 65 | with-chart: false 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /Readme.html 2 | 3 | composer.phar 4 | build/ 5 | vendor/ 6 | bin/composer 7 | env.sh 8 | .phpunit.cache 9 | .aider* 10 | .env 11 | -------------------------------------------------------------------------------- /.vscode/php-sdk.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": ".." 5 | } 6 | ], 7 | "settings": { 8 | "workbench.colorCustomizations": { 9 | "titleBar.activeForeground": "#232531", 10 | "titleBar.activeBackground": "#8993be" 11 | }, 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Versions 2 | 3 | ### [main](https://github.com/transloadit/php-sdk/tree/main) 4 | 5 | diff: https://github.com/transloadit/php-sdk/compare/3.2.0...main 6 | 7 | ### [3.2.0](https://github.com/transloadit/php-sdk/tree/3.2.0) 8 | 9 | - Implement `signedSmartCDNUrl` 10 | 11 | diff: https://github.com/transloadit/php-sdk/compare/3.1.0...3.2.0 12 | 13 | ### [3.1.0](https://github.com/transloadit/php-sdk/tree/3.1.0) 14 | 15 | - Pass down `curlOptions` when `TransloaditRequest` reinstantiates itself for `waitForCompletion` 16 | 17 | diff: https://github.com/transloadit/php-sdk/compare/3.0.4-dev...3.1.0 18 | 19 | ### [3.0.4-dev](https://github.com/transloadit/php-sdk/tree/3.0.4-dev) 20 | 21 | - Pass down `curlOptions` when `TransloaditRequest` reinstantiates itself for `waitForCompletion` 22 | 23 | diff: https://github.com/transloadit/php-sdk/compare/3.0.4...3.0.4-dev 24 | 25 | ### [3.0.4](https://github.com/transloadit/php-sdk/tree/3.0.4) 26 | 27 | - Ditch `v` prefix in versions as that's more idiomatic 28 | - Bring back the getAssembly() function 29 | - Implement Transloadit client header. Closes #25. (#28) 30 | - Fix waitForCompletion 31 | - Travis php & ubuntu version changes 32 | - fix: remove deprecation warning 33 | - Rename tl->deleteAssembly to cancelAssembly and add it to the Readme 34 | 35 | diff: https://github.com/transloadit/php-sdk/compare/v2.0.0...3.0.4 36 | 37 | ### [v2.1.0](https://github.com/transloadit/php-sdk/tree/v2.1.0) 38 | 39 | - Fix for CURL deprecated functions (thanks @ABerkhout) 40 | - CI improvements (phpunit, travis, composer) 41 | - Add example for fetching the assembly status 42 | - Add ability to set additional curl_setopt (thanks @michaelkasper) 43 | 44 | diff: https://github.com/transloadit/php-sdk/compare/v2.0.0...v2.1.0 45 | 46 | ### [v2.0.0](https://github.com/transloadit/php-sdk/tree/v2.0.0) 47 | 48 | - Retire host + protocol in favor of one endpoint property, 49 | allow passing that on to the Request object. 50 | - Improve readme (getting started) 51 | - Don't rely on globally installed phpunit when we can ship it via Composer 52 | 53 | diff: https://github.com/transloadit/php-sdk/compare/v1.0.1...v2.0.0 54 | 55 | ### [v1.0.1](https://github.com/transloadit/php-sdk/tree/v1.0.1) 56 | 57 | - Fix broken examples 58 | - Improve documentation (version changelogs) 59 | 60 | diff: https://github.com/transloadit/php-sdk/compare/v1.0.0...v1.0.1 61 | 62 | ### [v1.0.0](https://github.com/transloadit/php-sdk/tree/v1.0.0) 63 | 64 | A big thanks to [@nervetattoo](https://github.com/nervetattoo) for making this version happen! 65 | 66 | - Add support for Composer 67 | - Make phpunit run through Composer 68 | - Change to namespaced PHP 69 | 70 | diff: https://github.com/transloadit/php-sdk/compare/v0.10.0...v1.0.0 71 | 72 | ### [v0.10.0](https://github.com/transloadit/php-sdk/tree/v0.10.0) 73 | 74 | - Add support for Strict mode 75 | - Add support for more auth params 76 | - Improve documentation 77 | - Bug fixes 78 | - Refactoring 79 | 80 | diff: https://github.com/transloadit/php-sdk/compare/v0.9.1...v0.10.0 81 | 82 | ### [v0.9.1](https://github.com/transloadit/php-sdk/tree/v0.9.1) 83 | 84 | - Improve documentation 85 | - Better handling of errors & non-json responses 86 | - Change directory layout 87 | 88 | diff: https://github.com/transloadit/php-sdk/compare/v0.9...v0.9.1 89 | 90 | ### [v0.9](https://github.com/transloadit/php-sdk/tree/v0.9) 91 | 92 | - Use markdown for docs 93 | - Add support for signed GET requests 94 | - Add support for HTTPS 95 | - Simplified API 96 | - Improve handling of magic quotes 97 | 98 | diff: https://github.com/transloadit/php-sdk/compare/v0.2...v0.9 99 | 100 | ### [v0.2](https://github.com/transloadit/php-sdk/tree/v0.2) 101 | 102 | - Add error handling 103 | 104 | diff: https://github.com/transloadit/php-sdk/compare/v0.1...v0.2 105 | 106 | ### [v0.1](https://github.com/transloadit/php-sdk/tree/v0.1) 107 | 108 | The very first version 109 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2010 Transloadit 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /usr/bin/env bash 2 | 3 | export PATH := $(PATH):bin 4 | 5 | phpUnit = vendor/bin/phpunit --colors --verbose --stderr --configuration phpunit.xml $(2) $(1) 6 | 7 | .PHONY: install 8 | install: 9 | which composer || curl -sS https://getcomposer.org/installer | php -- --install-dir=bin --filename=composer 10 | composer install --no-interaction --prefer-source 11 | 12 | .PHONY: test 13 | test: test-simple 14 | 15 | .PHONY: test-all-coverage 16 | test-all-coverage: 17 | $(call phpUnit,test,--coverage-clover build/logs/clover.xml) 18 | 19 | .PHONY: test-all 20 | test-all: lint test-simple test-system 21 | 22 | .PHONY: test-simple 23 | test-simple: 24 | $(call phpUnit,test/simple) 25 | 26 | .PHONY: test-system 27 | test-system: 28 | $(call phpUnit,test/system) 29 | 30 | .PHONY: docs 31 | docs: 32 | php tool/generate-example-docs.php 33 | 34 | .PHONY: lint 35 | lint: 36 | @vendor/bin/phpcs --warning-severity=0 --standard=./phpcs.xml lib/ examples/ test/ tool/ 37 | 38 | .PHONY: fix 39 | fix: 40 | @vendor/bin/phpcbf --standard=./phpcs.xml lib/ examples/ test/ tool/ 41 | 42 | .PHONY: docs-html 43 | docs-html: docs 44 | Markdown.pl --html4tags Readme.md > Readme.html 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Transloadit PHP SDK 2 | 3 | [![Test Actions Status][test_badge]][test_link] 4 | [![Code coverage][codecov_badge]][codecov_link] 5 | ![Packagist PHP Version Support][php_verison_badge] 6 | [![License][licence_badge]][licence_link] 7 | 8 | ## Introduction 9 | 10 | The Transloadit PHP SDK provides a simple and efficient way to interact with Transloadit's file processing service in your PHP applications. With this SDK, you can easily: 11 | 12 | - Create and manage file upload assemblies 13 | - Use pre-defined templates for common file processing tasks 14 | - Handle notifications and retrieve assembly statuses 15 | - Integrate Transloadit's powerful file processing capabilities into your PHP projects 16 | 17 | This SDK simplifies the process of working with Transloadit's REST API, allowing you to focus on building great applications without worrying about the complexities of file processing. 18 | 19 | ## Install 20 | 21 | ``` 22 | composer require transloadit/php-sdk 23 | ``` 24 | 25 | Keep your Transloadit account's Auth Key & Secret nearby. You can check 26 | the [API credentials](https://transloadit.com/accounts/credentials) page for 27 | these values. 28 | 29 | ## Usage 30 | 31 | 32 | 33 | ### 1. Upload and resize an image from your server 34 | 35 | This example demonstrates how you can use the SDK to create an Assembly 36 | on your server. 37 | 38 | It takes a sample image file, uploads it to Transloadit, and starts a 39 | resizing job on it. 40 | 41 | ```php 42 | 'MY_TRANSLOADIT_KEY', 49 | 'secret' => 'MY_TRANSLOADIT_SECRET', 50 | ]); 51 | 52 | $response = $transloadit->createAssembly([ 53 | 'files' => ['/PATH/TO/FILE.jpg'], 54 | 'params' => [ 55 | 'steps' => [ 56 | 'resize' => [ 57 | 'robot' => '/image/resize', 58 | 'width' => 200, 59 | 'height' => 100, 60 | ], 61 | ], 62 | ], 63 | ]); 64 | 65 | // Show the results of the assembly we spawned 66 | echo '
'; 67 | print_r($response); 68 | echo ''; 69 | 70 | ``` 71 | 72 | ### 2. Create a simple end-user upload form 73 | 74 | This example shows you how to create a simple Transloadit upload form 75 | that redirects back to your site after the upload is done. 76 | 77 | Once the script receives the redirect request, the current status for 78 | this Assembly is shown using `Transloadit::response()`. 79 | 80 |
$response
is fetched. You should use
83 | the notify_url
parameter for this.
84 | '; 103 | print_r($response); 104 | echo ''; 105 | exit; 106 | } 107 | 108 | // This should work on most environments, but you might have to modify 109 | // this for your particular setup. 110 | $redirectUrl = sprintf('http://%s%s', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']); 111 | 112 | // Setup a simple file upload form that resizes an image to 200x100px 113 | echo $transloadit->createAssemblyForm([ 114 | 'params' => [ 115 | 'steps' => [ 116 | 'resize' => [ 117 | 'robot' => '/image/resize', 118 | 'width' => 200, 119 | 'height' => 100, 120 | ], 121 | ], 122 | 'redirect_url' => $redirectUrl, 123 | ], 124 | ]); 125 | ?> 126 |
'; 237 | print_r($response); 238 | echo ''; 239 | 240 | ``` 241 | 242 | ### 5. Create an Assembly with a Template. 243 | 244 | This example demonstrates how you can use the SDK to create an Assembly 245 | with Templates. 246 | 247 | You are expected to create a Template on your Transloadit account dashboard 248 | and add the Template ID here. 249 | 250 | ```php 251 | 'MY_TRANSLOADIT_KEY', 258 | 'secret' => 'MY_TRANSLOADIT_SECRET', 259 | ]); 260 | 261 | $response = $transloadit->createAssembly([ 262 | 'files' => ['/PATH/TO/FILE.jpg'], 263 | 'params' => [ 264 | 'template_id' => 'MY_TEMPLATE_ID', 265 | ], 266 | ]); 267 | 268 | // Show the results of the assembly we spawned 269 | echo '
'; 270 | print_r($response); 271 | echo ''; 272 | 273 | ``` 274 | 275 | ### Signature Auth (Assemblies) 276 | 277 | Signature Authentication is done by the PHP SDK by default internally so you do not need to worry about this :) 278 | 279 | ### Signature Auth (Smart CDN) 280 | 281 | You can use the `signedSmartCDNUrl` method to generate signed URLs for Transloadit's [Smart CDN](https://transloadit.com/services/content-delivery/): 282 | 283 | ```php 284 | 'MY_TRANSLOADIT_KEY', 291 | 'secret' => 'MY_TRANSLOADIT_SECRET', 292 | ]); 293 | 294 | // Basic usage 295 | $url = $transloadit->signedSmartCDNUrl( 296 | 'your-workspace-slug', 297 | 'your-template-slug', 298 | 'avatars/jane.jpg' 299 | ); 300 | 301 | // Advanced usage with custom parameters and expiry 302 | $url = $transloadit->signedSmartCDNUrl( 303 | 'your-workspace-slug', 304 | 'your-template-slug', 305 | 'avatars/jane.jpg', 306 | ['width' => 100, 'height' => 100], // Additional parameters 307 | 1732550672867, // Expiry date in milliseconds since epoch 308 | ); 309 | 310 | echo $url; 311 | ``` 312 | 313 | The generated URL will be in the format: 314 | 315 | ``` 316 | https://{workspace-slug}.tlcdn.com/{template-slug}/{input-field}?{query-params}&sig=sha256:{signature} 317 | ``` 318 | 319 | Note that: 320 | 321 | - The URL will expire after the specified time (default: 1 hour) 322 | - All parameters are properly encoded 323 | - The signature is generated using HMAC SHA-256 324 | - Query parameters are sorted alphabetically before signing 325 | 326 | ## Example 327 | 328 | For fully working examples take a look at [`examples/`](https://github.com/transloadit/php-sdk/tree/HEAD/examples). 329 | 330 | ## API 331 | 332 | ### $Transloadit = new Transloadit($properties = []); 333 | 334 | Creates a new Transloadit instance and applies the given $properties. 335 | 336 | #### $Transloadit->key = null; 337 | 338 | The auth key of your Transloadit account. 339 | 340 | #### $Transloadit->secret = null; 341 | 342 | The auth secret of your Transloadit account. 343 | 344 | #### $Transloadit->request($options = [], $execute = true); 345 | 346 | Creates a new `TransloaditRequest` using the `$Transloadit->key` and 347 | `$Transloadit->secret` properties. 348 | 349 | If `$execute` is set to `true`, `$TransloaditRequest->execute()` will be 350 | called and used as the return value. 351 | 352 | Otherwise the new `TransloaditRequest` instance is being returned. 353 | 354 | #### $Transloadit->createAssemblyForm($options = []); 355 | 356 | Creates a new Transloadit assembly form including the hidden 'params' and 357 | 'signature' fields. A closing form tag is not included. 358 | 359 | `$options` is an array of `TransloaditRequest` properties to be used. 360 | For example: `"params"`, `"expires"`, `"endpoint"`, etc.. 361 | 362 | In addition to that, you can also pass an `"attributes"` key, which allows 363 | you to set custom form attributes. For example: 364 | 365 | ```php 366 | $Transloadit->createAssemblyForm(array( 367 | 'attributes' => array( 368 | 'id' => 'my_great_upload_form', 369 | 'class' => 'transloadit_form', 370 | ), 371 | )); 372 | ``` 373 | 374 | #### $Transloadit->createAssembly($options); 375 | 376 | Sends a new assembly request to Transloadit. This is the preferred way of 377 | uploading files from your server. 378 | 379 | `$options` is an array of `TransloaditRequest` properties to be used with the exception that you can 380 | also use the `waitForCompletion` option here: 381 | 382 | `waitForCompletion` is a boolean (default is false) to indicate whether you want to wait for the 383 | Assembly to finish with all encoding results present before the callback is called. If 384 | waitForCompletion is true, this SDK will poll for status updates and return when all encoding work 385 | is done. 386 | 387 | Check example #1 above for more information. 388 | 389 | #### $Transloadit->getAssembly($assemblyId); 390 | 391 | Retrieves the Assembly status json for a given Assembly ID. 392 | 393 | #### $Transloadit->cancelAssembly($assemblyId); 394 | 395 | Cancels an assembly that is currently executing and prevents any further encodings costing money. 396 | 397 | This will result in `ASSEMBLY_NOT_FOUND` errors if invoked on assemblies that are not currently 398 | executing (anymore). 399 | 400 | #### Transloadit::response() 401 | 402 | This static method is used to parse the notifications Transloadit sends to 403 | your server. 404 | 405 | There are two kinds of notifications this method handles: 406 | 407 | - When using the `redirect_url` parameter, and Transloadit redirects 408 | back to your site, a `$_GET['assembly_url']` query parameter gets added. 409 | This method detects the presence of this parameter and fetches the current 410 | assembly status from that url and returns it as a `TransloaditResponse`. 411 | - When using the `notify_url` parameter, Transloadit sends a 412 | `$_POST['transloadit']` parameter. This method detects this, and parses 413 | the notification JSON into a `TransloaditResponse` object for you. 414 | 415 | If the current request does not seem to be invoked by Transloadit, this 416 | method returns `false`. 417 | 418 | ### $TransloaditRequest = new TransloaditRequest($properties = []); 419 | 420 | Creates a new TransloaditRequest instance and applies the given $properties. 421 | 422 | #### $TransloaditRequest->key = null; 423 | 424 | The auth key of your Transloadit account. 425 | 426 | #### $TransloaditRequest->secret = null; 427 | 428 | The auth secret of your Transloadit account. 429 | 430 | #### $TransloaditRequest->method = 'GET'; 431 | 432 | Inherited from `CurlRequest`. Can be used to set the type of request to be 433 | made. 434 | 435 | #### $TransloaditRequest->curlOptions = []; 436 | 437 | Inherited from `CurlRequest`. Can be used to tweak cURL behavior using [any cURL option that your PHP/cURL version supports](https://www.php.net/manual/en/function.curl-setopt.php). 438 | 439 | Here is an [example](examples/6-assembly-with-timeout.php) that illustrates 440 | using this option to change the timeout of a request (drastically, to `1ms`, just to prove you can make the SDK abort after a time of your choosing). 441 | 442 | The default timeouts and options depend on the cURL version on your system and can be verified by checking `phpinfo()` and the [curl_setopt](https://www.php.net/manual/en/function.curl-setopt.php) documentation. 443 | 444 | #### $TransloaditRequest->endpoint = 'https://api2.transloadit.com'; 445 | 446 | The endpoint to send this request to. 447 | 448 | #### $TransloaditRequest->path = null; 449 | 450 | The url path to request. 451 | 452 | #### $TransloaditRequest->url = null; 453 | 454 | Inherited from `CurlRequest`. Lets you overwrite the above endpoint / path 455 | properties with a fully custom url alltogether. 456 | 457 | #### $TransloaditRequest->fields = []; 458 | 459 | A list of additional fields to send along with your request. Transloadit 460 | will include those in all assembly related notifications. 461 | 462 | #### $TransloaditRequest->files = []; 463 | 464 | An array of paths to local files you would like to upload. For example: 465 | 466 | ```php 467 | $TransloaditRequest->files = array('/my/file.jpg'); 468 | ``` 469 | 470 | or 471 | 472 | ```php 473 | $TransloaditRequest->files = array('my_upload' => '/my/file.jpg'); 474 | ``` 475 | 476 | The first example would automatically give your file a field name of 477 | `'file_1'` when executing the request. 478 | 479 | #### $TransloaditRequest->params = []; 480 | 481 | An array representing the JSON params to be send to Transloadit. You 482 | do not have to include an `'auth'` key here, as this class handles that 483 | for you as part of `$TransloaditRequest->prepare()`. 484 | 485 | #### $TransloaditRequest->expires = '+2 hours'; 486 | 487 | If you have configured a '`$TransloaditRequest->secret`', this class will 488 | automatically sign your request. The expires property lets you configure 489 | the duration for which the signature is valid. 490 | 491 | #### $TransloaditRequest->headers = []; 492 | 493 | Lets you send additional headers along with your request. You should not 494 | have to change this property. 495 | 496 | #### $TransloaditRequest->execute() 497 | 498 | Sends this request to Transloadit and returns a `TransloaditResponse` 499 | instance. 500 | 501 | ### $TransloaditResponse = new TransloaditResponse($properties = []); 502 | 503 | Creates a new TransloaditResponse instance and applies the given $properties. 504 | 505 | #### $TransloaditResponse->data = null; 506 | 507 | Inherited from `CurlResponse`. Contains an array of the parsed JSON 508 | response from Transloadit. 509 | 510 | You should generally only access this property after having checked for 511 | errors using `$TransloaditResponse->error()`. 512 | 513 | #### $TransloaditResponse->error(); 514 | 515 | Returns `false` or a string containing an explanation of what went wrong. 516 | 517 | All of the following will cause an error string to be returned: 518 | 519 | - Network issues of any kind 520 | - The Transloadit response JSON contains an `{"error": "..."}` key 521 | - A malformed response was received 522 | 523 | **_Note_**: You will need to set waitForCompletion = True in the $Transloadit->createAssembly($options) function call. 524 | 525 | ## Contributing 526 | 527 | Feel free to fork this project. We will happily merge bug fixes or other small 528 | improvements. For bigger changes you should probably get in touch with us 529 | before you start to avoid not seeing them merged. 530 | 531 | ### Testing 532 | 533 | #### Basic Tests 534 | 535 | ```bash 536 | make test 537 | ``` 538 | 539 | #### System Tests 540 | 541 | System tests require: 542 | 543 | 1. Valid Transloadit credentials in environment: 544 | 545 | ```bash 546 | export TRANSLOADIT_KEY='your-auth-key' 547 | export TRANSLOADIT_SECRET='your-auth-secret' 548 | ``` 549 | 550 | Then run: 551 | 552 | ```bash 553 | make test-all 554 | ``` 555 | 556 | #### Node.js Reference Implementation Parity Assertions 557 | 558 | The SDK includes assertions that compare URL signing with our reference Node.js implementation. To run these tests: 559 | 560 | 1. Requirements: 561 | 562 | - Node.js installed 563 | - tsx installed globally (`npm install -g tsx`) 564 | 565 | 2. Install dependencies: 566 | 567 | ```bash 568 | npm install -g tsx 569 | ``` 570 | 571 | 3. Run the test: 572 | 573 | ```bash 574 | export TRANSLOADIT_KEY='your-auth-key' 575 | export TRANSLOADIT_SECRET='your-auth-secret' 576 | TEST_NODE_PARITY=1 make test-all 577 | ``` 578 | 579 | CI opts-into `TEST_NODE_PARITY=1`, and you can optionally do this locally as well. 580 | 581 | ### Releasing a new version 582 | 583 | To release, say `3.2.0` [Packagist](https://packagist.org/packages/transloadit/php-sdk), follow these steps: 584 | 585 | 1. Make sure `PACKAGIST_TOKEN` is set in your `.env` file 586 | 1. Make sure you are in main: `git checkout main` 587 | 1. Update `CHANGELOG.md` and `composer.json` 588 | 1. Commit: `git add CHANGELOG.md composer.json && git commit -m "Release 3.2.0"` 589 | 1. Tag, push, and release: `source env.sh && VERSION=3.2.0 ./release.sh` 590 | 591 | This project implements the [Semantic Versioning](http://semver.org/) guidelines. 592 | 593 | ## License 594 | 595 | [MIT Licensed](LICENSE) 596 | 597 | [test_badge]: https://github.com/transloadit/php-sdk/actions/workflows/ci.yml/badge.svg 598 | [test_link]: https://github.com/transloadit/php-sdk/actions/workflows/ci.yml 599 | [codecov_badge]: https://codecov.io/gh/transloadit/php-sdk/branch/main/graph/badge.svg 600 | [codecov_link]: https://codecov.io/gh/transloadit/php-sdk 601 | [php_verison_badge]: https://img.shields.io/packagist/php-v/transloadit/php-sdk 602 | [licence_badge]: https://img.shields.io/badge/License-MIT-green.svg 603 | [licence_link]: https://github.com/transloadit/php-sdk/blob/main/LICENSE 604 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "transloadit/php-sdk", 3 | "type": "library", 4 | "description": "Transloadit SDK", 5 | "keywords": [ 6 | "transloadit", 7 | "video", 8 | "encoding", 9 | "thumbnails", 10 | "image", 11 | "resizing", 12 | "audio", 13 | "waveform", 14 | "document", 15 | "processing", 16 | "file", 17 | "uploading" 18 | ], 19 | "homepage": "https://github.com/transloadit/php-sdk", 20 | "license": "MIT", 21 | "version": "3.1.0", 22 | "require": { 23 | "php": ">=7.4.0" 24 | }, 25 | "require-dev": { 26 | "php-coveralls/php-coveralls": "^2.5", 27 | "phpunit/phpunit": "^9.5", 28 | "squizlabs/php_codesniffer": "^3.7" 29 | }, 30 | "autoload": { 31 | "psr-0": { 32 | "transloadit": "lib" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/1-assembly-request.php: -------------------------------------------------------------------------------- 1 | Assembly 8 | on your server. 9 | 10 | It takes a sample image file, uploads it to Transloadit, and starts a 11 | resizing job on it. 12 | */ 13 | 14 | use transloadit\Transloadit; 15 | 16 | $transloadit = new Transloadit([ 17 | 'key' => 'MY_TRANSLOADIT_KEY', 18 | 'secret' => 'MY_TRANSLOADIT_SECRET', 19 | ]); 20 | 21 | $response = $transloadit->createAssembly([ 22 | // Use dirname(__FILE__) to get the current directory, then append the relative path to the image 23 | // You can replace this with an absolute path to any file on your server that PHP can access 24 | 'files' => [dirname(__FILE__) . '/fixture/straw-apple.jpg'], 25 | 'params' => [ 26 | 'steps' => [ 27 | 'resize' => [ 28 | 'robot' => '/image/resize', 29 | 'width' => 200, 30 | 'height' => 100, 31 | ], 32 | ], 33 | ], 34 | ]); 35 | 36 | // Show the results of the assembly we spawned 37 | echo '
'; 38 | print_r($response); 39 | echo ''; 40 | -------------------------------------------------------------------------------- /examples/2-assembly-form.php: -------------------------------------------------------------------------------- 1 | Assembly is shown using `Transloadit::response()`. 12 | 13 |
'; 33 | print_r($response); 34 | echo ''; 35 | exit; 36 | } 37 | 38 | // This should work on most environments, but you might have to modify 39 | // this for your particular setup. 40 | $redirectUrl = sprintf('http://%s%s', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']); 41 | 42 | // Setup a simple file upload form that resizes an image to 200x100px 43 | echo $transloadit->createAssemblyForm([ 44 | 'params' => [ 45 | 'steps' => [ 46 | 'resize' => [ 47 | 'robot' => '/image/resize', 48 | 'width' => 200, 49 | 'height' => 100, 50 | ], 51 | ], 52 | 'redirect_url' => $redirectUrl, 53 | ], 54 | ]); 55 | ?> 56 |
'; 24 | print_r($response); 25 | echo ''; 26 | exit; 27 | } 28 | 29 | $redirectUrl = sprintf('http://%s%s', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']); 30 | 31 | echo $transloadit->createAssemblyForm([ 32 | 'params' => [ 33 | 'steps' => [ 34 | 'resize' => [ 35 | 'robot' => '/image/resize', 36 | 'width' => 200, 37 | 'height' => 100, 38 | ], 39 | ], 40 | 'redirect_url' => $redirectUrl, 41 | ], 42 | ]); 43 | ?> 44 | 48 | 49 | 53 | 59 | 60 |
'; 20 | print_r($response); 21 | echo ''; 22 | -------------------------------------------------------------------------------- /examples/5-assembly-with-template.php: -------------------------------------------------------------------------------- 1 | Assembly 8 | with Templates. 9 | 10 | You are expected to create a Template on your Transloadit account dashboard 11 | and add the Template ID here. 12 | */ 13 | 14 | use transloadit\Transloadit; 15 | 16 | $transloadit = new Transloadit([ 17 | 'key' => 'MY_TRANSLOADIT_KEY', 18 | 'secret' => 'MY_TRANSLOADIT_SECRET', 19 | ]); 20 | 21 | $response = $transloadit->createAssembly([ 22 | 'files' => [dirname(__FILE__) . '/fixture/straw-apple.jpg'], 23 | 'params' => [ 24 | 'template_id' => 'MY_TEMPLATE_ID', 25 | ], 26 | ]); 27 | 28 | // Show the results of the assembly we spawned 29 | echo '
'; 30 | print_r($response); 31 | echo ''; 32 | -------------------------------------------------------------------------------- /examples/6-assembly-with-timeout.php: -------------------------------------------------------------------------------- 1 | getenv('MY_TRANSLOADIT_KEY'), 9 | 'secret' => getenv('MY_TRANSLOADIT_SECRET'), 10 | ]); 11 | 12 | $response = $transloadit->createAssembly([ 13 | 'files' => [dirname(__FILE__) . '/fixture/straw-apple.jpg'], 14 | 'curlOptions' => [ 15 | CURLOPT_TIMEOUT_MS => 1, 16 | // We can't finish in the specified: '1ms' so we expect this example 17 | // to fail with: $response->curlErrorNumber === 28 18 | // 19 | // You can pass any curl option here that your PHP/curl version supports: 20 | // https://www.php.net/manual/en/function.curl-setopt.php 21 | // Note that if you are interested in timeouts, perhaps also consider 22 | // that you can set waitForCompletion to false and use the 23 | // notify_url feature to get a webhook pingback when the Assembly is done. 24 | ], 25 | 'params' => [ 26 | 'steps' => [ 27 | 'resize' => [ 28 | 'robot' => '/image/resize', 29 | 'width' => 200, 30 | 'height' => 100, 31 | ], 32 | ], 33 | ], 34 | ]); 35 | 36 | // Show the results of the assembly we spawned 37 | echo '