PHP code example of zamzar / zamzar-php

1. Go to this page and download the library: Download zamzar/zamzar-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/ */

    

zamzar / zamzar-php example snippets







// Connect to the Production API using an API Key
$zamzar = new \Zamzar\ZamzarClient('apikey');


// Use the Production API
$zamzar = new \Zamzar\ZamzarClient([
    'api_key' => 'apiKey',
    'environment' => 'production'
]);


// Use the Sandbox API
$zamzar = new \Zamzar\ZamzarClient([
    'api_key' => 'apiKey',
    'environment' => 'sandbox'
]);



echo $zamzar->testConnection();


// Submit the file
$job = $zamzar->jobs->create([
    'source_file' => 'path/to/local/file',
    'target_format' => 'xxx'
]);

// Wait for the job to complete (the default timeout is 60 seconds)
$job->waitForCompletion(30);

// Download the converted files 
$job->downloadTargetFiles('path/to/folder/');

// Delete the source and target files on Zamzar's servers
$job->deleteAllFiles();

// Do the whole thing together
$job = $zamzar->jobs->create([
        'source_file' => 'path/to/localfile', 
        'target_format' => 'pdf'
    ])
    ->waitForCompletion(120)
    ->downloadTargetFiles('path/to/folder')
    ->deleteAllFiles();

$client = new Zamzar\ZamzarClient([
    'api_key' = '****',
    'debug' => true,
]);

// PSR-3 Compatible Logger
\Zamzar\Zamzar::setLogger($psr3Logger);

// Using Monolog
$logger = new Logger('Zamzar');
$logger->pushHandler(new StreamHandler(__DIR__.'/app.log', Logger::DEBUG));
\Zamzar\Zamzar::setLogger($logger);
bash
composer