PHP code example of fliq / ipfs-laravel

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

    

fliq / ipfs-laravel example snippets


$cid = Ipfs::add('Hello, IPFS')->first()['Hash'];

Ipfs::get($cid); // Hello, IPFS

$resource = fopen('path/to/file.mp3');

$results = Ipfs::add([
    'hello.txt' => 'Hello, IPFS!', 
    'file.mp3' => $resource,
    'meta.json' => [
        'name' => 'Hello',
        'properties' => [...],
    ],
], ['wrap-with-directory' => true]);

$cid = $results->last()['Hash'];

Ipfs::get("{$cid}/hello.txt"); // Hello, IPFS!

$stream = Ipfs::cat($cid);

$str = Ipfs::get($cid);

$array = Ipfs::json($cid);

Ipfs::async()->add($file)->then(function(array $results) {
    $results[0]; // do something
});

// or do multiple requests.
$ipfs = Ipfs::async();

$promises = [
    $ipfs->get($cid1),
    $ipfs->get($cid2),
];

$results = GuzzleHttp\Promise\Utils::unwrap($promises);
bash
php artisan vendor:publish --tag=ipfs.config