zamzar/zamzar-php
Composer 安装命令:
composer require zamzar/zamzar-php
包简介
Zamzar PHP Library
关键字:
README 文档
README
Easy to use PHP file conversion API with support for 1,100+ file conversions - convert documents, audio, images, video,
eBooks and more. Use zamzar-php to convert files between different formats as part of your PHP application with
the Zamzar file conversion API. Common use cases include:
- Convert Microsoft Word (DOCX, DOC) to PDF
- Extract text from PDF files
- Convert Powerpoint (PPT, PPTX) to JPG
- Archive email (MSG files) to PDF
This is the official PHP SDK for the Zamzar file conversion API.
Jump to:
- Requirements
- Installation
- Initialise the Zamzar Client
- Test the Connection
- Typical Usage
- Configure a Logger
- Resources
Requirements
- Before you begin, signup for a Zamzar API Account or retrieve your existing API Key from the Zamzar Developers Homepage
- PHP 7.2.34 and later.
Installation
You can install the bindings via Composer. Run the following command:
composer require zamzar/zamzar-php
To use the bindings, use Composer's autoload:
require_once('vendor/autoload.php');
Initialise the Zamzar Client
To initialise the client, declare a new ZamzarClient:
// Connect to the Production API using an API Key $zamzar = new \Zamzar\ZamzarClient([ 'api_key' => 'apiKey', 'transport' => \Zamzar\ZamzarClient::recommendedTransport() ]);
To specify whether the client using the Production or Test API, use a Config array:
// Use the Production API $zamzar = new \Zamzar\ZamzarClient([ 'api_key' => 'apiKey', 'environment' => 'production', 'transport' => \Zamzar\ZamzarClient::recommendedTransport() ]); // Use the Sandbox API $zamzar = new \Zamzar\ZamzarClient([ 'api_key' => 'apiKey', 'environment' => 'sandbox', 'transport' => \Zamzar\ZamzarClient::recommendedTransport() ]);
Test the Connection
To confirm your credentials are correct, test the connection to the API which will return a welcome message and confirm which API you are using (Production or Test).
echo $zamzar->testConnection();
Typical Usage
The most common requirement is to submit a job to convert a file, wait for the job to complete, download the converted files and delete the files on Zamzar servers.
// 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();
The above use case might be applied when other things are happening in between each step, but if not, and you want to chain the whole thing together:
// Do the whole thing together $job = $zamzar->jobs->create([ 'source_file' => 'path/to/localfile', 'target_format' => 'pdf' ]) ->waitForCompletion(120) ->downloadTargetFiles('path/to/folder') ->deleteAllFiles();
Configure a Logger
The library does minimal logging, if the debug config option is used. Use either the supplied default logger or a
psr-3 compatible logger.
$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);
Resources
Code Samples - Copy/Paste from examples which demonstrate all key areas of functionality.
Exceptions Handling - Learn more about API Error Codes.
Developer Docs - For more information about API operations, parameters, and responses. Use this if you need additional context on all areas of functionality.
zamzar/zamzar-php 适用场景与选型建议
zamzar/zamzar-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 59.96k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2021 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「zamzar」 「file conversion」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zamzar/zamzar-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zamzar/zamzar-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zamzar/zamzar-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
A PSR-7 compatible library for making CRUD API endpoints
Laravel Media Popup to upload/view the files
PMVC Plugin for File information
Mapper for accessing resources in KWCMS
Text file manipulation
统计信息
- 总下载量: 59.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-07