PHP API Client

PHP integration handles uploads and file operations by wrapping Uploadcare Upload API and REST API. This comprehensive API client lets you use most of the Uploadcare features from within your PHP app.

GitHub →

Check out an example project that we created as a showcase for various usage scenarios and tasks that you can resolve.

Features

Uploading (Upload API):

  • Upload files from local storage and URLs (up to 5 TB)
  • Multipart uploading for large files
  • Uploading network to speed uploading jobs (like CDN)

File management (REST API):

  • Get file info and perform various operations (store/delete/copy) with them
  • Work with groups of files
  • Manage webhooks
  • Remove image background
  • Recognize objects on the picture
  • Check for viruses
  • Convert documents
  • Encode and transform videos

Image processing (URL API):

  • Compression
  • Geometry
  • Colors
  • Definition
  • Image and text overlays
  • Rotations
  • Recognition
  • File info
  • Proxy (fetch)

Security features:

  • Secure authentication
  • Secure uploads (signed uploads)
  • Secure delivery (signed URLs)
  • Secure webhooks (signing secret)

Requirements

  • PHP 7.4 and later or PHP 8 and later
  • php-curl
  • php-json

How to check PHP version via CLI:

php -v

How to check modules:

php -m

You should see curl and json in the list:

workstation:home user$ php -m
[PHP Modules]
bcmath
...
curl
...
json
...

[Zend Modules]

Install

Prior to installing uploadcare-php, get the Composer dependency manager for PHP to simplify installation.

1. Update

  1. Update composer.json:
"require": {
    "uploadcare/uploadcare-php": "^4.0"
}

2. Run

Run Composer:

php composer.phar update

3. Define

Define Uploadcare API keys:

Add API keys to your configuration object. For example:

# config.php
$_ENV['UPLOADCARE_PUBLIC_KEY'] = '<your public key>';
$_ENV['UPLOADCARE_SECRET_KEY'] = '<your secret key>';

4. Include Composer

Include Composer's autoload file:

require_once 'vendor/autoload.php';

5. Create a configuration object

There're a few ways to create a configuration object. We recommend that you use this static method of the Uploadcare\Configuration class:

$configuration = Uploadcare\Configuration::create($_ENV['UPLOADCARE_PUBLIC_KEY'], $_ENV['UPLOADCARE_SECRET_KEY']);

Alternatively, you can create a Security signature, HTTP client, and Serializer classes explicitly. After that, you can create a configuration object:

$sign = new \Uploadcare\Security\Signature('<your private 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);

As you can see, the factory method is more convenient for standard usage.

That's it! All further operations will use this configuration object.

Usage example

Now that you have Uploadcare PHP API client up and running, you can do the following: