ecourty / ipfs-php
A lightweight IPFS interaction library for PHP
1.0.0
2025-03-12 19:50 UTC
Requires
- php: >= 8.3
- symfony/http-client: ^7.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.71
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.0
- symfony/var-dumper: ^7.2
README
IPFS-PHP provides a simple way to interact with an IPFS Node using PHP.
Installation
composer require ecourty/ipfs-php
Usage
The following example shows how to add a file to IPFS and retrieve its content later.
<?php use IPFS\Client\IPFSClient; // Three different ways to instantiate the client $client = new IPFSClient(url: 'http://localhost:5001'); // If nothing is passed, the default values are used (localhost and 5001) // $client = new IPFSClient(); // $client = new IPFSClient(host: 'localhost', port: 5001); // Add a file $fileContent = file_get_contents('file.txt'); $file = $client->add($fileContent); echo 'File uploaded: ' . $file->hash; // File uploaded: QmWGeRAEgtsHW3ec7U4qW2CyVy7eA2mFRVbk1nb24jFyks // ... // Get the file content $fileContent = $client->cat($file->hash); // ... // Downloads the complete file $file = $client->get($file->hash); // ... // Download the file as a tar archive (compression can be specified with the compression parameters) $archive = $client->get($file->hash, archive: true); file_put_contents('archive.tar', $archive); // ...
More code examples can be found under the examples directory.
© Edouard Courty 2025