The pdfRest Zip Files API Tool provides a convenient way to programmatically zip multiple files together. This API is particularly useful when dealing with a collection of documents that need to be compressed into a single archive for easier distribution or storage. By using this API, developers can automate the process of zipping files directly from their PHP applications, saving time and reducing the potential for human error.
In a real-world scenario, a user might need to zip a collection of financial reports, project documents, or a batch of images to send as a single attachment via email. The pdfRest Zip Files API allows users to do this directly from their web application, without the need for manual intervention or desktop zip utilities. This streamlines workflows, especially when dealing with large numbers of files or when this process needs to be repeated regularly.
require 'vendor/autoload.php'; use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Utils; $client = new Client(); $headers = [ 'Api-Key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' ]; $options = [ 'multipart' => [ [ 'name' => 'file', 'contents' => Utils::tryFopen('/path/to/file1', 'r'), 'filename' => '/path/to/file1', 'headers' => [ 'Content-Type' => '' ] ], [ 'name' => 'file', 'contents' => Utils::tryFopen('/path/to/file2', 'r'), 'filename' => '/path/to/file2', 'headers' => [ 'Content-Type' => ' ' ] ], [ 'name' => 'id[]', 'contents' => 'xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' ], [ 'name' => 'output', 'contents' => 'pdfrest_zip' ] ]]; $request = new Request('POST', 'https://api.pdfrest.com/zip', $headers); $res = $client->sendAsync($request, $options)->wait(); echo $res->getBody();
Reference to the provided code: GitHub Repository.
The code provided is a PHP script that uses the Guzzle HTTP client to send a POST request to the pdfRest API to zip files together. The script includes the following components:
Each 'multipart' array element represents a part of the request payload:
According to the pdfRest Cloud API Reference Guide, each parameter in the request is essential for the API to understand what files to include and how to format the response.
This tutorial has demonstrated how to use PHP to call the pdfRest Zip Files API to compress multiple files into a single zip archive. By following the provided code example and understanding each part of the code, you can integrate this functionality into your PHP applications.
To further explore and demo all of the pdfRest API Tools, visit the API Lab. For more detailed information on other endpoints and parameters, refer to the API Reference Guide.
Note: This is an example of a multipart API call. Code samples using JSON payloads for the pdfRest API can be found at GitHub Repository.
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.