vier / ipfs-api
IPFS API 的最小实现
此包的规范仓库似乎已不存在,因此包已被冻结。
dev-master
2022-03-29 11:23 UTC
Requires
- php: >=5.6.0
- ext-curl: *
This package is not auto-updated.
Last update: 2024-01-13 01:23:51 UTC
README
IPFS API 的最小实现。
使用说明
安装
此库需要 PHP 5.7 以及 curl 和 json 扩展。
$ composer require vier/ipfs-api:dev-master
$ composer install
use vier\IpfsApi\Ipfs;
// connect to ipfs daemon API server
$ipfs = new IPFS("localhost", 5001, "http://yourdomain/ipfs"); // leaving out the arguments will default to these values
API
add
向 IPFS 添加内容。
用法
$hash = $ipfs->add("Hello world");
addFromPath
从文件名添加内容到 IPFS(辅助方法)
用法
$hash = $ipfs->addFromPath("myFile.txt");
addFromUrl
从网页 URL 添加内容到 IPFS(辅助方法)
用法
$hash = $ipfs->addFromUrl('https://mysite.com/img.png');
get
检索单个哈希的内容。
用法
$ipfs->get($hash);
ls
获取哈希的节点结构。
用法
$nodes = $ipfs->ls($hash);
foreach ($nodes as $node) {
echo $node['Hash'];
echo $node['Size'];
echo $node['Name'];
}
对象大小
返回对象大小。
用法
$size = $ipfs->size($hash);
Pin
固定或取消固定一个哈希。
用法
$ipfs->pinAdd($hash);
$ipfs->pinRm($hash);
ID
获取您的 ipfs 节点的信息。
用法
print_r($ipfs->id());