1. Go to this page and download the library: Download uploadcare/uploadcare-php 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/ */
$configuration = \Uploadcare\Configuration::create('<your public key>', '<your secret key>');
$sign = new \Uploadcare\Security\Signature('<your secret key>', 3600); // Must be an instance of \Uploadcare\Interfaces\SignatureInterface
$client = \Uploadcare\Client\ClientFactory::createClient(); // Must be an instance of \GuzzleHttp\ClientInterface
$serializer = new \Uploadcare\Serializer\Serializer(new \Uploadcare\Serializer\SnackCaseConverter()); // Must be an instance of \Uploadcare\Interfaces\Serializer\SerializerInterface
$configuration = new \Uploadcare\Configuration('<your public key>', $sign, $client, $serializer);
$configuration = \Uploadcare\Configuration::create($_ENV['UPLOADCARE_PUBLIC_KEY'], $_ENV['UPLOADCARE_SECRET_KEY']);
$api = new \Uploadcare\Api($configuration);
$configuration = \Uploadcare\Configuration::create($_ENV['UPLOADCARE_PUBLIC_KEY'], $_ENV['UPLOADCARE_SECRET_KEY']);
$uploader = (new \Uploadcare\Api($configuration))->uploader();
$url = 'https://httpbin.org/image/jpeg';
$result = $uploader->fromUrl($url, 'image/jpeg'); // If success, $result will be string to check upload status (see below)
$url = 'https://httpbin.org/image/jpeg';
$result = $uploader->fromUrl($url, 'image/jpeg');
$status = $uploader->checkStatus($result); // Instance of Uploadcare\Interfaces\File\FileInfoInterface with isReady() === false until file is not uploaded.
$path = __DIR__ . '/squirrel.jpg';
$result = $uploader->fromPath($path, 'image/jpeg'); // In success $result will contain uploaded Uploadcare\File class
$request = new \Uploadcare\Conversion\VideoEncodingRequest();
$request = (new \Uploadcare\Conversion\VideoEncodingRequest())
->setHorizontalSize(1024) // Sets the horizontal size for result.
->setVerticalSize(768) // Sets the vertical size of result.
->setResizeMode('preserve_ratio') // Sets the resize mode. Mode can be one of 'preserve_ratio', 'change_ratio', 'scale_crop', 'add_padding'
->setQuality('normal') // Sets result quality. Can be one of 'normal', 'better', 'best', 'lighter', 'lightest'
->setTargetFormat('mp4') // Sets the target format. Can be one of 'webm', 'ogg', 'mp4'. Default 'mp4'
->setStartTime('0:0') // Sets the start time. Time string must be an `HHH:MM:SS.sss` or `MM:SS.sss`
->setEndTime('22:44') // Sets the end time. String format like start time string
->setThumbs(2) // Sets count of video thumbs. Default 1, max 50
->setStore(true) // Tells store result at conversion ends. Default is true
use Uploadcare\Configuration;
use Uploadcare\AuthUrl\AuthUrlConfig;
use Uploadcare\Api;
use Uploadcare\AuthUrl\Token\AkamaiToken;
$authUrlConfig = new AuthUrlConfig('mydomain.com', new AkamaiToken('secretKey', 300));
$config = Configuration::create($_ENV['UPLOADCARE_PUBLIC_KEY'], $_ENV['UPLOADCARE_SECRET_KEY'])
->setAuthUrlConfig($authUrlConfig);
$api = new Api($config);
$file = $api->file()->listFiles()->getResults()->first();
// Get secure url from file
$secureUrl = $file->generateSecureUrl(); // you can use KeyCdnUrlGenerator or AkamaiUrlGenerator
// Or from API instance
$secureUrlFromApi = $api->file()->generateSecureUrl($file);
$api->file()->generateSecureUrl('/*/'); # Access to all files in project
$api->file()->generateSecureUrl('/{uuid}/-/resize/640x/other/transformations/'); # Access to modified file version
json
""uploadcare/uploadcare-php": "^4.0"
}
bash
php composer.phar update
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.