transloadit/php-sdk
transloadit/php-sdk — 61★ trên GitHub (PHP). Transloadit's official PHP SDK
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Snapshot
Cộng tác viên hàng đầu
Xem cộng tác viên hàng đầu
Transloadit PHP SDK
Introduction
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:
- Create and manage file upload assemblies
- Use pre-defined templates for common file processing tasks
- Handle notifications and retrieve assembly statuses
- Integrate Transloadit's powerful file processing capabilities into your PHP projects
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.
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
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' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_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
This example shows you how to create a simple Transloadit upload form that redirects back to your site after the upload is done.
Once the script receives the redirect request, the current status for
this Assembly is shown using Transloadit::response().
$response is fetched. You should use
the notify_url parameter for this.
<?php
require 'vendor/autoload.php';
use transloadit\Transloadit;
$transloadit = new Transloadit([
'key' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_TRANSLOADIT_SECRET',
]);
// Check if this request is a Transloadit redirect_url notification.
// If so fetch the response and output the current assembly status:
$response = Transloadit::response();
if ($response) {
echo '<h1>Assembly Status:</h1>';
echo '<pre>';
print_r($response);
echo '</pre>';
exit;
}
// This should work on most environments, but you might have to modify
// this for your particular setup.
$redirectUrl = sprintf('http://%s%s', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);
// Setup a simple file upload form that resizes an image to 200x100px
echo $transloadit->createAssemblyForm([
'params' => [
'steps' => [
'resize' => [
'robot' => '/image/resize',
'width' => 200,
'height' => 100,
],
],
'redirect_url' => $redirectUrl,
],
]);
?>
<h1>Pick an image to resize</h1>
<input name="example_upload" type="file">
<input type="submit" value="Upload">
</form>
3. Use Uppy for file uploads
We recommend using Uppy, our next-gen file uploader for the web, instead of the jQuery SDK. Uppy provides a more modern, flexible, and feature-rich solution for handling file uploads with Transloadit.
To integrate Uppy with your PHP backend:
- Include Uppy in your HTML:
<link
href="https://releases.transloadit.com/uppy/v3.3.1/uppy.min.css"
rel="stylesheet"
/>
<script src="https://releases.transloadit.com/uppy/v3.3.1/uppy.min.js"></script>
- Initialize Uppy with Transloadit plugin:
<div id="uppy"></div>
<script>
const uppy = new Uppy.Core()
.use(Uppy.Dashboard, {
inline: true,
target: '#uppy'
})
.use(Uppy.Transloadit, {
params: {
auth: { key: 'MY_TRANSLOADIT_KEY' },
template_id: 'MY_TEMPLATE_ID',
notify_url: 'https://your-site.com/transloadit_notify.php'
}
})
uppy.on('complete', (result) => {
console.log('Upload complete! We've uploaded these files:', result.successful)
})
</script>
- Handle the assembly status on your PHP backend:
Create a new file named transloadit_notify.php in your project:
<?php
require 'vendor/autoload.php';
use transloadit\Transloadit;
$transloadit = new Transloadit([
'key' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_TRANSLOADIT_SECRET',
]);
$response = Transloadit::response();
if ($response) {
// Process the assembly result
$assemblyId = $response->data['assembly_id'];
$assemblyStatus = $response->data['ok'];
// You can store the assembly information in your database
// or perform any other necessary actions here
// Log the response for debugging
error_log('Transloadit Assembly Completed: ' . $assemblyId);
error_log('Assembly Status: ' . ($assemblyStatus ? 'Success' : 'Failed'));
// Optionally, you can write the response to a file
file_put_contents('transloadit_response_' . $assemblyId . '.json', json_encode($response->data));
// Send a 200 OK response to Transloadit
http_response_code(200);
echo 'OK';
} else {
// If it's not a Transloadit notification, return a 400 Bad Request
http_response_code(400);
echo 'Bad Request';
}
?>
Make sure to replace 'https://your-site.com/transloadit_notify.php' with the actual URL where you'll host this PHP script.
For more detailed information on using Uppy with Transloadit, please refer to our Uppy documentation.
4. Fetch the Assembly Status JSON
You can use the getAssembly method to get the Assembly Status.
<?php
require 'vendor/autoload.php';
$assemblyId = 'MY_ASSEMBLY_ID';
$transloadit = new Transloadit([
'key' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_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' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_TRANSLOADIT_SECRET',
]);
$response = $transloadit->createAssembly([
'files' => ['/PATH/TO/FILE.jpg'],
'params' => [
'template_id' => 'MY_TEMPLATE_ID',
],
]);
// Show the results of the assembly we spawned
echo '<pre>';
print_r($response);
echo '</pre>';
Signature Auth (Assemblies)
Signature Authentication is done by the PHP SDK by default internally so you do not need to worry about this :)
If you script the same request payload multiple times in quick succession (for example inside a health check or tight integration test loop), add a random nonce to keep each signature unique:
$params = [
'auth' => [
'key' => 'MY_TRANSLOADIT_KEY',
'expires' => gmdate('Y/m/d H:i:s+00:00', strtotime('+2 hours')),
'nonce' => bin2hex(random_bytes(16)),
],
'steps' => [
// …
],
];
The nonce is optional for regular usage, but including it in heavily scripted flows prevents Transloadit from rejecting repeated identical signatures.
Signature Auth (Smart CDN)
You can use the signedSmartCDNUrl method to generate signed URLs for Transloadit's Smart CDN:
<?php
require 'vendor/autoload.php';
use transloadit\Transloadit;
$transloadit = new Transloadit([
'key' => 'MY_TRANSLOADIT_KEY',
'secret' => 'MY_TRANSLOADIT_SECRET',
]);
// Basic usage
$url = $transloadit->signedSmartCDNUrl(
'your-workspace-slug',
'your-template-slug',
'avatars/jane.jpg'
);
// Advanced usage with custom parameters and expiry
$url = $transloadit->signedSmartCDNUrl(
'your-workspace-slug',
'your-template-slug',
'avatars/jane.jpg',
['width' => 100, 'height' => 100], // Additional parameters
1732550672867, // Expiry date in milliseconds since epoch
);
echo $url;
The generated URL will be in the format:
https://{workspace-slug}.tlcdn.com/{template-slug}/{input-field}?{query-params}&sig=sha256:{signature}
Note that:
- The URL will expire after the specified time (default: 1 hour)
- All parameters are properly encoded
- The signature is generated using HMAC SHA-256
- Query parameters are sorted alphabetically before signing
Example
For fully working examples take a look at examples/.
API
$Transloadit = new Transloadit($properties = []);
Creates a new Transloadit instance and applies the given $properties.
$Transloadit->key = null;
The auth key of your Transloadit account.
$Transloadit->secret = null;
The auth secret of your Transloadit account.
$Transloadit->signatureAlgorithm = 'sha384';
Controls which HMAC algorithm is used for Assembly request signing.
The default is 'sha384' (recommended). If you need compatibility with a legacy key,
you can set this to 'sha1'.
$Transloadit->request($options = [], $execute = true);
Creates a new TransloaditRequest using the $Transloadit->key and
$Transloadit->secret properties.
If $execute is set to true, $TransloaditRequest->execute() will be
called and used as the return value.
Otherwise the new TransloaditRequest instance is being returned.
$Transloadit->createAssemblyForm($options = []);
Creates a new Transloadit assembly form including the hidden 'params' and 'signature' fields. A closing form tag is not included.
$options is an array of TransloaditRequest properties to be used.
For example: "params", "expires", "endpoint", etc..
In addition to that, you can also pass an "attributes" key, which allows
you to set custom form attributes. For example:
$Transloadit->createAssemblyForm(array(
'attributes' => array(
'id' => 'my_great_upload_form',
'class' => 'transloadit_form',
),
));
$Transloadit->createAssembly($options);
Sends a new assembly request to Transloadit. This is the preferred way of uploading files from your server.
$options is an array of TransloaditRequest properties to be used with the exception that you can
also use the waitForCompletion option here:
waitForCompletion is a boolean (default is false) to indicate whether you want to wait for the
Assembly to finish with all encoding results present before the callback is called. If
waitForCompletion is true, this SDK will poll for status updates and return when all encoding work
is done.
Check example #1 above for more information.
$Transloadit->getAssembly($assemblyId);
Retrieves the Assembly status json for a given Assembly ID.
$Transloadit->cancelAssembly($assemblyId);
Cancels an assembly that is currently executing and prevents any further encodings costing money.
This will result in ASSEMBLY_NOT_FOUND errors if invoked on assemblies that are not currently
executing (anymore).
Transloadit::response()
This static method is used to parse the notifications Transloadit sends to your server.
There are two kinds of notifications this method handles:
- When using the
redirect_urlparameter, and Transloadit redirects back to your site, a$_GET['assembly_url']query parameter gets added. This method detects the presence of this parameter and fetches the current assembly status from that url and returns it as aTransloaditResponse. - When using the
notify_urlparameter, Transloadit sends a$_POST['transloadit']parameter. This method detects this, and parses the notification JSON into aTransloaditResponseobject for you.
If the current request does not seem to be invoked by Transloadit, this
method returns false.
$TransloaditRequest = new TransloaditRequest($properties = []);
Creates a new TransloaditRequest instance and applies the given $properties.
$TransloaditRequest->key = null;
The auth key of your Transloadit account.
$TransloaditRequest->secret = null;
The auth secret of your Transloadit account.
$TransloaditRequest->signatureAlgorithm = 'sha384';
Controls which HMAC algorithm is used when preparing the Assembly request signature.
The generated signature field uses the <algorithm>:<digest> format, for example:
sha384:....
$TransloaditRequest->method = 'GET';
Inherited from CurlRequest. Can be used to set the type of request to be
made.
$TransloaditRequest->curlOptions = [];
Inherited from CurlRequest. Can be used to tweak cURL behavior using any cURL option that your PHP/cURL version supports.
Here is an example that illustrates
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).
The default timeouts and options depend on the cURL version on your system and can be verified by checking phpinfo() and the curl_setopt documentation.
$TransloaditRequest->endpoint = 'https://api2.transloadit.com';
The endpoint to send this request to.
$TransloaditRequest->path = null;
The url path to request.
$TransloaditRequest->url = null;
Inherited from CurlRequest. Lets you overwrite the above endpoint / path
properties with a fully custom url alltogether.
$TransloaditRequest->fields = [];
A list of additional fields to send along with your request. Transloadit will include those in all assembly related notifications.
$TransloaditRequest->files = [];
An array of paths to local files you would like to upload. For example:
$TransloaditRequest->files = array('/my/file.jpg');
or
$TransloaditRequest->files = array('my_upload' => '/my/file.jpg');
The first example would automatically give your file a field name of
'file_1' when executing the request.
$TransloaditRequest->params = [];
An array representing the JSON params to be send to Transloadit. You
do not have to include an 'auth' key here, as this class handles that
for you as part of $TransloaditRequest->prepare().
$TransloaditRequest->expires = '+2 hours';
If you have configured a '$TransloaditRequest->secret', this class will
automatically sign your request. The expires property lets you configure
the duration for which the signature is valid.
$TransloaditRequest->headers = [];
Lets you send additional headers along with your request. You should not have to change this property.
$TransloaditRequest->execute()
Sends this request to Transloadit and returns a TransloaditResponse
instance.
$TransloaditResponse = new TransloaditResponse($properties = []);
Creates a new TransloaditResponse instance and applies the given $properties.
$TransloaditResponse->data = null;
Inherited from CurlResponse. Contains an array of the parsed JSON
response from Transloadit.
You should generally only access this property after having checked for
errors using $TransloaditResponse->error().
$TransloaditResponse->error();
Returns false or a string containing an explanation of what went wrong.
All of the following will cause an error string to be returned:
- Network issues of any kind
- The Transloadit response JSON contains an
{"error": "..."}key - A malformed response was received
Note: You will need to set waitForCompletion = True in the $Transloadit->createAssembly($options) function call.
License
MIT Licensed
Repo liên quan
Laravel is an open-source PHP web application framework maintained at laravel/laravel, bundling a routing engine, dependency injection, the Eloquent ORM, schema migrations, queue processing, and event broadcasting into one framework. It's MIT-licensed, documents support for AI coding agents through the separate Laravel Boost package, and points to Laracasts and Laravel Learn for getting started.
Public APIs is a community-curated GitHub repository listing free, publicly accessible APIs across a wide range of categories, with auth type, HTTPS, and CORS noted for each entry. It's a browsable reference, not a library to install.
Awesome-Selfhosted is a community-maintained GitHub list at awesome-selfhosted/awesome-selfhosted that catalogs Free Software network-service and web-app projects meant for running on a server you control rather than someone else's cloud. Entries are grouped by category, each tagged with a license and a language or deployment option, and the project keeps proprietary alternatives on a separate Non-Free page.
Awesome Python is a curated list maintained at vinta/awesome-python that groups Python frameworks, libraries, tools, and other resources into 14 categories, from AI & ML to Security and Other. The README calls it an opinionated guide rather than an exhaustive one, and points readers to a companion site, awesome-python.com, for searching and filtering entries instead of scrolling the raw file.
Trả lời nhanh
Cùng nhóm Backend còn repo nào?
transloadit/php-sdk thuộc nhóm Backend trên TopGit, cùng 4 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về transloadit/php-sdk ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/transloadit/php-sdk là nguồn chính thức.
transloadit/php-sdk có bao nhiêu sao?
transloadit/php-sdk có 61 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/transloadit/php-sdk. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
transloadit/php-sdk có những chủ đề gì?
GitHub topics của transloadit/php-sdk: "encoding", "php", "transloadit", "uploading". TopGit xếp repo vào nhóm Backend.
transloadit/php-sdk còn đang phát triển không?
Commit gần nhất trên transloadit/php-sdk là 27 ngày trước (theo timestamp GitHub). Repo có 21 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
transloadit/php-sdk viết bằng ngôn ngữ gì?
transloadit/php-sdk chủ yếu viết bằng PHP. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Vì sao transloadit/php-sdk được xếp vào nhóm Backend?
TopGit xếp transloadit/php-sdk vào nhóm Backend dựa trên GitHub topics và mô tả của repo (gắn thẻ: "encoding", "php", "transloadit"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
Đọc đầy đủ README ở tab phía trên.
Chưa chắc php-sdk có hợp với bạn?
Để ChatGPT, Claude hoặc Perplexity tìm hiểu giúp — bấm bên dưới và xem AI nói gì về php-sdk.