PHP code example of cloutier / php-ipfs-api

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

    

cloutier / php-ipfs-api example snippets


use Cloutier\PhpIpfsApi\IPFS;

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

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

$ipfs->cat($hash);

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

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

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

$ipfs->pinAdd($hash);
$ipfs->pinRm($hash);

print_r($ipfs->id());