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.
Check out an example project that showcases various usage scenarios.
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 laterorPHP 8 and laterphp-curlphp-json
How to check PHP version via CLI:
How to check modules:
You should see curl and json in the list:
Install
Prior to installing uploadcare-php, get the Composer
dependency manager for PHP to simplify installation.
1. Update
- Update
composer.json:
This constraint resolves to the latest v4.x release. Current stable version is 4.2.1.
2. Run
Run Composer:
3. Define
Define Uploadcare API keys:
Add API keys to your configuration object. For example:
4. Include Composer
Include Composer’s autoload file:
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:
Alternatively, you can create a Security signature, HTTP client, and Serializer classes explicitly. After that, you can create a configuration object:
As you can see, the factory method is more convenient for standard usage.
The factory method Configuration::create() is recommended for standard usage. The manual constructor is available for advanced scenarios such as custom HTTP clients or serializers.
That’s it! All further operations will use this configuration object.
Quick start
Upload
Upload from path
Upload from URL
Synchronous upload from URL (blocks until done)
Upload from content
Upload with metadata
File operations
Get file info
Store a file
Delete a file
File metadata
Copy
Copy to local storage
Copy to remote storage
Secure delivery
The Akamai secret key must be a hex string (characters a-f, 0-9, even length). A non-hex placeholder will throw a TokenException.
generateSecureUrl returns null if AuthUrlConfig is not set on the configuration object.
Webhooks
File conversion
Document conversion
Document conversion to group (multi-page)
Usage example
For a full list of supported operations, see the uploadcare-php GitHub repository and the example project.