PHP SDK
Our PHP SDK allows you to automate the uploading of files through the Transloadit REST API using PHP.
It can be installed via Composer.
Install
composer require transloadit/php-sdk
Keep your Transloadit account's Auth Key & Secret nearby. You can check the API credentials page for these values.
Usage
Run the PHP examples below in trusted server-side scripts. Keep the Auth Secret on your server; authorize users before allowing them to trigger uploads or request Assembly results.
1. Upload and resize an image from your server
This example demonstrates how you can use the SDK to create an Assembly on your server.
It takes a sample image file, uploads it to Transloadit, and starts a resizing job on it.
<?php
require 'vendor/autoload.php';
use transloadit\Transloadit;
$transloadit = new Transloadit([
'key' => 'YOUR_TRANSLOADIT_KEY',
'secret' => 'YOUR_TRANSLOADIT_SECRET',
]);
$response = $transloadit->createAssembly([
'files' => ['/PATH/TO/FILE.jpg'],
'params' => [
'steps' => [
'resize' => [
'robot' => '/image/resize',
'width' => 200,
'height' => 100,
],
],
],
]);
// Show the results of the assembly we spawned
echo '<pre>';
print_r($response);
echo '</pre>';
2. Create a simple end-user upload form
For browser uploads, follow the Uppy integration below. It keeps signing on your server and uploads files directly from the browser to Transloadit.
For processing-completion notifications, follow the signature-verification instructions in the
Webhooks API documentation. A browser redirect does not prove that an
Assembly has finished. Transloadit::response() parses
incoming notification data; it does not authenticate it. Creating a Transloadit instance with a
secret does not make that static method verify a webhook.
3. Use Uppy for file uploads
We recommend Uppy for browser uploads. Start with the canonical Uppy and Transloadit guide for Template setup, server signing, and framework-specific client examples.
Your PHP backend must authenticate the user and authorize the upload before signing short-lived Assembly options. Choose the allowed Template and Instructions on the server. Do not sign arbitrary parameters from the browser. See Signature Authentication for the signing protocol and the webhook documentation above for verifying completion notifications.
4. Fetch the Assembly Status JSON
You can use the getAssembly method to get the Assembly Status.
<?php
require 'vendor/autoload.php';
use transloadit\Transloadit;
$assemblyId = 'YOUR_ASSEMBLY_ID';
$transloadit = new Transloadit([
'key' => 'YOUR_TRANSLOADIT_KEY',
'secret' => 'YOUR_TRANSLOADIT_SECRET',
]);
$response = $transloadit->getAssembly($assemblyId);
echo '<pre>';
print_r($response);
echo '</pre>';
5. Create an Assembly with a Template.
This example demonstrates how you can use the SDK to create an Assembly with Templates.
You are expected to create a Template on your Transloadit account dashboard and add the Template ID here.
<?php
require 'vendor/autoload.php';
use transloadit\Transloadit;
$transloadit = new Transloadit([
'key' => 'YOUR_TRANSLOADIT_KEY',
'secret' => 'YOUR_TRANSLOADIT_SECRET',
]);
$response = $transloadit->createAssembly([
'files' => ['/PATH/TO/FILE.jpg'],
'params' => [
'template_id' => 'YOUR_TEMPLATE_ID',
],
]);
// Show the results of the assembly we spawned
echo '<pre>';
print_r($response);
echo '</pre>';
Signature Auth
The PHP SDK signs outgoing API requests with your configured Auth Secret using Signature Authentication. Incoming webhooks require separate signature verification as described in the webhook documentation.
Example
For fully working examples take a look at
examples/.
Documentation
See GitHub for the full documentation.