PHP code example of nathansalter / php-ipfs-api

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

    

nathansalter / php-ipfs-api example snippets


use NathanSalter\PhpIpfsApi\IpfsClient;

// connect to ipfs daemon API server
$ipfs = new IpfsClient("localhost", "8080", "5001"); // leaving out the arguments will default to these values

$hash = $ipfs->add('Hello world');

$ipfs->cat($hash);

$hashes = $ipfs->ls($hash);

foreach ($hashes as $e) {
    echo $e['Hash'];
    echo $e['Size'];
    echo $e['Name'];
}

$size = $ipfs->size($hash);

$ipfs->pinAdd($hash);