PHP code example of rannmann / php-ipfs-api

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

    

rannmann / php-ipfs-api example snippets


use rannmann\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");

$hash = $ipfs->addFromPath("myFile.txt");

$hash = $ipfs->addFromUrl('https://mysite.com/img.png');

$ipfs->get($hash);

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

foreach ($nodes as $node) {
	echo $node['Hash'];
	echo $node['Size'];
	echo $node['Name'];
}

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

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

print_r($ipfs->id());