1. Go to this page and download the library: Download transloadit/php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
transloadit / php-sdk example snippets
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>';
transloadit\Transloadit;
$transloadit = new Transloadit([
'key' => 'YOUR_TRANSLOADIT_KEY',
'secret' => 'YOUR_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,
],
]);
transloadit\Transloadit;
$transloadit = new Transloadit([
'key' => 'YOUR_TRANSLOADIT_KEY',
'secret' => 'YOUR_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';
}