PHPackages                             cloudconvert/cloudconvert-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. cloudconvert/cloudconvert-php

ActiveLibrary[API Development](/categories/api)

cloudconvert/cloudconvert-php
=============================

PHP SDK for CloudConvert APIs

3.4.3(5mo ago)2253.5M↓47.7%907PHPPHP ^7.4|^8.0CI failing

Since Mar 8Pushed 3mo ago36 watchersCompare

[ Source](https://github.com/cloudconvert/cloudconvert-php)[ Packagist](https://packagist.org/packages/cloudconvert/cloudconvert-php)[ Docs](https://github.com/cloudconvert/cloudconvert-php)[ RSS](/packages/cloudconvert-cloudconvert-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (12)Versions (25)Used By (7)

cloudconvert-php
================

[](#cloudconvert-php)

This is the official PHP SDK for the [CloudConvert](https://cloudconvert.com/api/v2) **API v2**.

[![Tests](https://github.com/cloudconvert/cloudconvert-php/actions/workflows/run-tests.yml/badge.svg)](https://github.com/cloudconvert/cloudconvert-php/actions/workflows/run-tests.yml)[![Latest Stable Version](https://camo.githubusercontent.com/8b053cb4914c516b0e6b0221513c49a125d552565f25568030528f0983558761/68747470733a2f2f706f7365722e707567782e6f72672f636c6f7564636f6e766572742f636c6f7564636f6e766572742d7068702f762f737461626c65)](https://packagist.org/packages/cloudconvert/cloudconvert-php)[![Total Downloads](https://camo.githubusercontent.com/eb54578c10295328aff66484579cb94da5faa0812ccf82284788cfa8ed27324f/68747470733a2f2f706f7365722e707567782e6f72672f636c6f7564636f6e766572742f636c6f7564636f6e766572742d7068702f646f776e6c6f616473)](https://packagist.org/packages/cloudconvert/cloudconvert-php)

Install
-------

[](#install)

To install the PHP SDK you will need to be using Composer in your project.

Install the SDK alongside Guzzle:

```
composer require cloudconvert/cloudconvert-php guzzlehttp/guzzle
```

This package is not tied to any specific HTTP client by using [PSR-7](https://www.php-fig.org/psr/psr-7/), [PSR-17](https://www.php-fig.org/psr/psr-17/), [PSR-18](https://www.php-fig.org/psr/psr-18/), and [HTTPlug](https://httplug.io/). Therefore, you will also need to install packages that provide [`psr/http-client-implementation`](https://packagist.org/providers/psr/http-client-implementation) and [`psr/http-factory-implementation`](https://packagist.org/providers/psr/http-factory-implementation) (for example Guzzle).

Creating Jobs
-------------

[](#creating-jobs)

```
use \CloudConvert\CloudConvert;
use \CloudConvert\Models\Job;
use \CloudConvert\Models\Task;

$cloudconvert = new CloudConvert([
    'api_key' => 'API_KEY',
    'sandbox' => false
]);

$job = (new Job())
    ->setTag('myjob-1')
    ->addTask(
        (new Task('import/url', 'import-my-file'))
            ->set('url','https://my-url')
    )
    ->addTask(
        (new Task('convert', 'convert-my-file'))
            ->set('input', 'import-my-file')
            ->set('output_format', 'pdf')
            ->set('some_other_option', 'value')
    )
    ->addTask(
        (new Task('export/url', 'export-my-file'))
            ->set('input', 'convert-my-file')
    );

$cloudconvert->jobs()->create($job)
```

You can use the [CloudConvert Job Builder](https://cloudconvert.com/api/v2/jobs/builder) to see the available options for the various task types.

Uploading Files
---------------

[](#uploading-files)

Uploads to CloudConvert are done via `import/upload` tasks (see the [docs](https://cloudconvert.com/api/v2/import#import-upload-tasks)). This SDK offers a convenient upload method:

```
use \CloudConvert\Models\Job;
use \CloudConvert\Models\Task;

$job = (new Job())
    ->addTask(new Task('import/upload','upload-my-file'))
    ->addTask(
        (new Task('convert', 'convert-my-file'))
            ->set('input', 'upload-my-file')
            ->set('output_format', 'pdf')
    )
    ->addTask(
        (new Task('export/url', 'export-my-file'))
            ->set('input', 'convert-my-file')
    );

$job = $cloudconvert->jobs()->create($job);

$uploadTask = $job->getTasks()->whereName('upload-my-file')[0];

$cloudconvert->tasks()->upload($uploadTask, fopen('./file.pdf', 'r'), 'file.pdf');
```

The `upload()` method accepts a string, PHP resource or PSR-7 `StreamInterface` as second parameter.

You can also directly allow clients to upload files to CloudConvert:

```
